Rev 726 | Rev 787 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
206 | jmachado | 1 | package pt.estgp.estgweb.utils; |
2 | |||
678 | jmachado | 3 | import jomm.utils.MyCalendar; |
206 | jmachado | 4 | import pt.estgp.estgweb.Globals; |
5 | |||
6 | import java.text.MessageFormat; |
||
678 | jmachado | 7 | import java.text.SimpleDateFormat; |
8 | import java.util.ArrayList; |
||
9 | import java.util.List; |
||
206 | jmachado | 10 | |
11 | /** |
||
12 | * @author Jorge Machado |
||
13 | * @date 13/Jun/2008 |
||
14 | * @see pt.estgp.estgweb.utils |
||
15 | */ |
||
16 | public class DatesUtils |
||
17 | { |
||
18 | |||
19 | static 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat SIGES_importFirstYearFormat = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat(Globals.SIGES_importFirstYearFormat); |
||
20 | static 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat SIGES_importSecondYearFormat = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat(Globals.SIGES_importSecondYearFormat); |
||
21 | static 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat SIGES_importFinalFormat = new 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat(Globals.SIGES_importFinalFormat); |
||
22 | |||
214 | jmachado | 23 | static 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat SIGES_importFirstYearFormatIntranet = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat(Globals.SIGES_importFirstYearFormatIntranet); |
24 | static 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat SIGES_importSecondYearFormatIntranet = new 1.5.0/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat(Globals.SIGES_importSecondYearFormatIntranet); |
||
25 | static 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat SIGES_importFinalFormatIntranet = new 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat(Globals.SIGES_importFinalFormatIntranet); |
||
726 | jmachado | 26 | static 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat SIGES_importFinalFormatProgram = new 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat(Globals.SIGES_importFinalFormatProgram); |
214 | jmachado | 27 | |
206 | jmachado | 28 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYear() |
29 | { |
||
724 | jmachado | 30 | return ConfigProperties.getProperty("import.year"); |
31 | // MyCalendar mc = new MyCalendar(); |
||
32 | // int month = mc.getMonth(); |
||
33 | // MyCalendar firstYear; |
||
34 | // MyCalendar secondYear; |
||
35 | // if(month <= 9) |
||
36 | // { |
||
37 | // firstYear = new MyCalendar(mc.getYear() - 1,1,1); |
||
38 | // secondYear = new MyCalendar(mc.getYear(),1,1); |
||
39 | // } |
||
40 | // else |
||
41 | // { |
||
42 | // firstYear = new MyCalendar(mc.getYear(),1,1); |
||
43 | // secondYear = new MyCalendar(mc.getYear()+1,1,1); |
||
44 | // } |
||
45 | // |
||
46 | // String firstYearStr = SIGES_importFirstYearFormat.format(firstYear.getTime()); |
||
47 | // String secondYearStr = SIGES_importSecondYearFormat.format(secondYear.getTime()); |
||
48 | // |
||
49 | // return getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormat); |
||
206 | jmachado | 50 | } |
51 | |||
343 | jmachado | 52 | public static 1.5.0/docs/api/java/lang/String.html">String getSemestre() |
53 | { |
||
54 | MyCalendar mc = new MyCalendar(); |
||
55 | int month = mc.getMonth(); |
||
56 | if((month > 8 && month <=12) || (month >= 1 && month <=2)) |
||
57 | { |
||
58 | return "S1"; |
||
59 | } |
||
60 | else |
||
61 | { |
||
62 | return "S2"; |
||
63 | } |
||
64 | } |
||
65 | |||
767 | jmachado | 66 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYearBefore(1.5.0/docs/api/java/lang/String.html">String year) { |
67 | 1.5.0/docs/api/java/lang/String.html">String year1 = year.substring(0,4); |
||
68 | |||
69 | int year1Int = 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(year1); |
||
70 | |||
71 | year1Int -= 1; |
||
72 | int year2Int = year1Int + 1; |
||
73 | 1.5.0/docs/api/java/lang/String.html">String part2 = ("" + year2Int).substring(2); |
||
74 | |||
75 | 1.5.0/docs/api/java/lang/String.html">String yearTarget = "" + year1Int + part2; |
||
76 | |||
77 | return yearTarget; |
||
78 | } |
||
79 | |||
371 | jmachado | 80 | public static enum SemestreModerate |
81 | { |
||
82 | S1, |
||
83 | S2, |
||
84 | S1S2 |
||
85 | } |
||
86 | |||
87 | public static SemestreModerate getSemestreModerate() |
||
88 | { |
||
89 | MyCalendar mc = new MyCalendar(); |
||
90 | int month = mc.getMonth(); |
||
91 | if(month > 8 && month <=12) |
||
92 | { |
||
93 | return SemestreModerate.S1; |
||
94 | } |
||
95 | else if(month >= 1 && month <=3) |
||
96 | { |
||
97 | return SemestreModerate.S1S2; |
||
98 | } |
||
99 | else |
||
100 | { |
||
101 | return SemestreModerate.S2; |
||
102 | } |
||
103 | } |
||
104 | |||
214 | jmachado | 105 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYearIntranet() |
206 | jmachado | 106 | { |
214 | jmachado | 107 | MyCalendar mc = new MyCalendar(); |
108 | int month = mc.getMonth(); |
||
109 | MyCalendar firstYear; |
||
110 | MyCalendar secondYear; |
||
111 | if(month <= 8) |
||
112 | { |
||
113 | firstYear = new MyCalendar(mc.getYear() - 1,1,1); |
||
114 | secondYear = new MyCalendar(mc.getYear(),1,1); |
||
115 | } |
||
116 | else |
||
117 | { |
||
118 | firstYear = new MyCalendar(mc.getYear(),1,1); |
||
119 | secondYear = new MyCalendar(mc.getYear()+1,1,1); |
||
120 | } |
||
121 | |||
122 | 1.5.0/docs/api/java/lang/String.html">String firstYearStr = SIGES_importFirstYearFormatIntranet.format(firstYear.getTime()); |
||
123 | 1.5.0/docs/api/java/lang/String.html">String secondYearStr = SIGES_importSecondYearFormatIntranet.format(secondYear.getTime()); |
||
124 | |||
125 | return getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormatIntranet); |
||
126 | } |
||
127 | |||
345 | jmachado | 128 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYearIntranet(1.5.0/docs/api/java/lang/String.html">String importYear) |
129 | { |
||
130 | 1.5.0/docs/api/java/lang/String.html">String decadeStr = importYear.substring(0,2); |
||
131 | if(importYear.substring(4,6).equals("00")) |
||
132 | { |
||
133 | 1.5.0/docs/api/java/lang/String.html">String decade = importYear.substring(0,2); |
||
134 | int nextdecade= 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(decade)+1; |
||
135 | decadeStr = "" + nextdecade; |
||
136 | } |
||
137 | return getFormatedImportYear(importYear.substring(0,4),decadeStr+importYear.substring(4,6),SIGES_importFinalFormatIntranet); |
||
138 | } |
||
139 | |||
726 | jmachado | 140 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYearPrograms(1.5.0/docs/api/java/lang/String.html">String importYear) |
141 | { |
||
142 | |||
143 | return getFormatedImportYear(importYear.substring(0,4),importYear.substring(4,6),SIGES_importFinalFormatProgram); |
||
144 | } |
||
145 | |||
214 | jmachado | 146 | public static 1.5.0/docs/api/java/lang/String.html">String getFormatedImportYear(1.5.0/docs/api/java/lang/String.html">String firstYearStr, 1.5.0/docs/api/java/lang/String.html">String secondYearStr, 1.5.0/docs/api/java/text/MessageFormat.html">MessageFormat finalFormat) |
147 | { |
||
206 | jmachado | 148 | 1.5.0/docs/api/java/lang/String.html">String[] years = {firstYearStr,secondYearStr}; |
214 | jmachado | 149 | return finalFormat.format(years); |
206 | jmachado | 150 | } |
151 | |||
152 | public static List<String> getImportYears(int size) |
||
153 | { |
||
154 | MyCalendar mc = new MyCalendar(); |
||
155 | int month = mc.getMonth(); |
||
156 | MyCalendar firstYear; |
||
157 | MyCalendar secondYear; |
||
158 | if(month <= 8) |
||
159 | { |
||
160 | firstYear = new MyCalendar(mc.getYear() - 1,1,1); |
||
161 | secondYear = new MyCalendar(mc.getYear(),1,1); |
||
162 | } |
||
163 | else |
||
164 | { |
||
165 | firstYear = new MyCalendar(mc.getYear(),1,1); |
||
166 | secondYear = new MyCalendar(mc.getYear()+1,1,1); |
||
167 | } |
||
168 | |||
169 | 1.5.0/docs/api/java/lang/String.html">String firstYearStr = SIGES_importFirstYearFormat.format(firstYear.getTime()); |
||
170 | 1.5.0/docs/api/java/lang/String.html">String secondYearStr = SIGES_importSecondYearFormat.format(secondYear.getTime()); |
||
171 | |||
172 | List<String> importYears = new ArrayList<String>(); |
||
214 | jmachado | 173 | importYears.add(getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormat)); |
206 | jmachado | 174 | |
175 | for(int i = 0; i < size;i++) |
||
176 | { |
||
177 | firstYear = new MyCalendar(firstYear.getYear() - 1,1,1); |
||
178 | secondYear = new MyCalendar(secondYear.getYear() - 1,1,1); |
||
179 | firstYearStr = SIGES_importFirstYearFormat.format(firstYear.getTime()); |
||
180 | secondYearStr = SIGES_importSecondYearFormat.format(secondYear.getTime()); |
||
214 | jmachado | 181 | importYears.add(getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormat)); |
206 | jmachado | 182 | } |
183 | return importYears; |
||
184 | } |
||
185 | |||
215 | jmachado | 186 | public static List<String> getYears(int size) |
187 | { |
||
188 | List<String> years = new ArrayList<String>(); |
||
189 | MyCalendar c = new MyCalendar(); |
||
190 | for(int i = c.getYear(); i > c.getYear() - size;i-- ) |
||
191 | years.add("" + i); |
||
192 | return years; |
||
193 | } |
||
194 | |||
206 | jmachado | 195 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) |
196 | { |
||
767 | jmachado | 197 | 1.5.0/docs/api/java/lang/System.html">System.out.println(getImportYearBefore("200001")); |
726 | jmachado | 198 | 1.5.0/docs/api/java/lang/System.html">System.out.println(getImportYear()); |
206 | jmachado | 199 | } |
200 | } |