001 package org.apache.myfaces.tobago.model;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020 import java.util.Calendar;
021 import java.util.Locale;
022
023 public class DateModel {
024
025 private int year;
026 private int month;
027 private int day;
028
029 public DateModel(int year, int month, int day) {
030 this.year = year;
031 this.month = month;
032 this.day = day;
033 }
034
035 public DateModel(Calendar calendar) {
036 this.year = calendar.get(Calendar.YEAR);
037 this.month = calendar.get(Calendar.MONTH) + 1;
038 this.day = calendar.get(Calendar.DAY_OF_MONTH);
039 }
040
041 public int getYear() {
042 return year;
043 }
044
045 public void setYear(int year) {
046 this.year = year;
047 }
048
049 public int getMonth() {
050 return month;
051 }
052
053 public void setMonth(int month) {
054 this.month = month;
055 }
056
057 public int getDay() {
058 return day;
059 }
060
061 public void setDay(int day) {
062 this.day = day;
063 }
064
065 public Calendar getCalendar() {
066 return getCalendar(null);
067 }
068
069 public Calendar getCalendar(Locale locale) {
070 Calendar calendar = locale != null
071 ? Calendar.getInstance(locale) : Calendar.getInstance();
072 calendar.set(year, month - 1, day);
073 return calendar;
074 }
075
076 }