View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.model;
21  
22  import java.util.Calendar;
23  import java.util.Locale;
24  
25  public class DateModel {
26  
27    private int year;
28    private int month;
29    private int day;
30  
31    public DateModel(final int year, final int month, final int day) {
32      this.year = year;
33      this.month = month;
34      this.day = day;
35    }
36  
37    public DateModel(final Calendar calendar) {
38      this.year = calendar.get(Calendar.YEAR);
39      this.month = calendar.get(Calendar.MONTH) + 1;
40      this.day = calendar.get(Calendar.DAY_OF_MONTH);
41    }
42  
43    public int getYear() {
44      return year;
45    }
46  
47    public void setYear(final int year) {
48      this.year = year;
49    }
50  
51    public int getMonth() {
52      return month;
53    }
54  
55    public void setMonth(final int month) {
56      this.month = month;
57    }
58  
59    public int getDay() {
60      return day;
61    }
62  
63    public void setDay(final int day) {
64      this.day = day;
65    }
66  
67    public Calendar getCalendar() {
68      return getCalendar(null);
69    }
70  
71    public Calendar getCalendar(final Locale locale) {
72      final Calendar calendar = locale != null
73          ? Calendar.getInstance(locale) : Calendar.getInstance();
74      calendar.set(year, month - 1, day);
75      return calendar;
76    }
77  
78  }