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