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.formbackingbeans;
20  
21  import java.util.Calendar;
22  import java.util.Date;
23  import java.util.TimeZone;
24  
25  import org.promotego.beans.Location;
26  
27  public class GameOfferBean
28  {
29      private int duration;
30      private Location location;
31      private int hour;
32      private int minute;
33      private int day;
34      private int month;
35      private int year;
36      private int ampm;
37      private boolean m_hoursValid;
38  
39      public int getDuration()
40      {
41          return this.duration;
42      }
43  
44      public void setDuration(int duration)
45      {
46          this.duration = duration;
47      }
48  
49      public Location getLocation()
50      {
51          return this.location;
52      }
53  
54      public void setLocation(Location location)
55      {
56          this.location = location;
57      }
58  
59      public int getDay()
60      {
61          return day;
62      }
63  
64      public void setDay(int day)
65      {
66          this.day = day;
67      }
68  
69      public int getHour()
70      {
71          return hour;
72      }
73  
74      public void setHour(int hours)
75      {
76          this.hour = hours;
77      }
78  
79      public int getMinute()
80      {
81          return minute;
82      }
83  
84      public void setMinute(int minutes)
85      {
86          this.minute = minutes;
87      }
88  
89      public int getMonth()
90      {
91          return month;
92      }
93  
94      public void setMonth(int month)
95      {
96          this.month = month;
97      }
98  
99      public int getYear()
100     {
101         return year;
102     }
103 
104     public void setYear(int year)
105     {
106         this.year = year;
107     }
108 
109     public int getAmpm()
110     {
111         return ampm;
112     }
113 
114     public void setAmpm(int ampm)
115     {
116         this.ampm = ampm;
117     }
118 
119 	/***
120 	 * @return
121 	 */
122 	public Date getStartTime()
123 	{
124 		// TODO Get a calendar for the location's time zone
125 	    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles"));
126 	    int hour = getHour();
127 	    if (hour == 12)
128 	    {
129 	        if (getAmpm() == Calendar.AM)
130 	        {
131 	            hour = 0;
132 	        }
133 	    }
134 	    else if (getAmpm() == Calendar.PM)
135 	    {
136 	        hour += 12;
137 	    }
138 	    calendar.set(getYear(), getMonth(), getDay(), hour, getMinute(), 0);
139 	    
140 	    Date startTime = calendar.getTime();
141 		return startTime;
142 	}
143 
144     public boolean isHoursValid()
145     {
146         return m_hoursValid;
147     }
148 
149     public void setHoursValid(boolean hoursValid)
150     {
151         m_hoursValid = hoursValid;
152     }
153 
154     /***
155      * Given a calendar, set all the appropriate fields.
156      * 
157      * @param theCalendar A calendar containing the date to be set for the start time
158      */
159     public void setStartTime(Calendar theCalendar)
160     {
161         setYear(theCalendar.get(Calendar.YEAR));
162         setMonth(theCalendar.get(Calendar.MONTH));
163         setDay(theCalendar.get(Calendar.DAY_OF_MONTH));
164         setHour(theCalendar.get(Calendar.HOUR));
165         setMinute(theCalendar.get(Calendar.MINUTE));
166         setAmpm(theCalendar.get(Calendar.AM_PM));
167     }
168 }