View Javadoc

1   /*
2    * Copyright (C) 2007 Alf Mikula
3    * 
4    * This file is part of PromoteGo.
5    *
6    * PromoteGo is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * PromoteGo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with PromoteGo.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.promotego.helpers;
20  
21  import java.text.DecimalFormat;
22  import java.text.NumberFormat;
23  import java.util.Calendar;
24  import java.util.TimeZone;
25  
26  import org.promotego.viewbeans.NamedValueBean;
27  
28  public class DateHelper
29  {
30      private static int[] hours;
31      private static NamedValueBean[] minutes;
32      private static int[] years;
33      private static int[] days;
34  
35      /***
36       * The months of the year, and their corresponding numeric values.
37       * 
38       * TODO Localize names of months
39       */
40      private static NamedValueBean [] months = {
41          new NamedValueBean("January", Calendar.JANUARY),
42          new NamedValueBean("February", Calendar.FEBRUARY),
43          new NamedValueBean("March", Calendar.MARCH),
44          new NamedValueBean("April", Calendar.APRIL),
45          new NamedValueBean("May", Calendar.MAY),
46          new NamedValueBean("June", Calendar.JUNE),
47          new NamedValueBean("July", Calendar.JULY),
48          new NamedValueBean("August", Calendar.AUGUST),
49          new NamedValueBean("September", Calendar.SEPTEMBER),
50          new NamedValueBean("October", Calendar.OCTOBER),
51          new NamedValueBean("November", Calendar.NOVEMBER),
52          new NamedValueBean("December", Calendar.DECEMBER)
53      };
54      
55      private static final int MINUTE_INCREMENT = 15;
56      private static final int NUM_YEARS = 2;
57  
58      /***
59       * The increments allowed for game durations.
60       * 
61       * TODO localize "hour/hours".
62       */
63      private static NamedValueBean [] durations = {
64          new NamedValueBean("1 hour", 3600),
65          new NamedValueBean("1.5 hours", 5400),
66          new NamedValueBean("2 hours", 7200),
67          new NamedValueBean("3 hours", 10800),
68          new NamedValueBean("4 hours", 14400),
69      };
70      
71      private static NamedValueBean [] ampm = {
72          new NamedValueBean("AM", Calendar.AM),
73          new NamedValueBean("PM", Calendar.PM)
74      };
75      
76      static { init(); }
77  
78      private static void init()
79      {
80          hours = new int[12];
81          for (int i=1; i<=12; i++) { hours[i-1] = i; }
82          
83          minutes = new NamedValueBean[60/MINUTE_INCREMENT];
84          NumberFormat numberFormat = new DecimalFormat("00");
85          
86          for (int i=0; i<60; i+=MINUTE_INCREMENT)
87          {
88              NamedValueBean nvBean = new NamedValueBean();
89              nvBean.setValue(i);
90              nvBean.setName(numberFormat.format(i));
91              minutes[i/MINUTE_INCREMENT] = nvBean;
92          }
93          
94          // TODO Use a real date picker in the UI that has some understanding
95          // of a limit in terms of how far out to allow the user to pick a date.
96          years = new int[NUM_YEARS];
97          int currentYear = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles")).get(Calendar.YEAR);
98          for (int i=0; i<NUM_YEARS; i++)
99          {
100             years[i] = currentYear + i;
101         }
102         
103         days = new int[31];
104         for (int i=0; i<31; i++)
105         {
106             days[i] = i+1;
107         }
108     }
109 
110     public static int[] getDays()
111     {
112         return days;
113     }
114 
115     public static int[] getHours()
116     {
117         return hours;
118     }
119 
120     public static NamedValueBean[] getMinutes()
121     {
122         return minutes;
123     }
124 
125     public static NamedValueBean[] getMonths()
126     {
127         return months;
128     }
129 
130     public static NamedValueBean[] getDurations()
131     {
132         return durations;
133     }
134 
135     public static int[] getYears()
136     {
137         return years;
138     }
139     
140     public static NamedValueBean[] getAmpm()
141     {
142         return ampm;
143     }
144 }