Rev 723 | Rev 726 | 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); |
||
26 | |||
206 | jmachado | 27 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYear() |
28 | { |
||
724 | jmachado | 29 | return ConfigProperties.getProperty("import.year"); |
30 | // MyCalendar mc = new MyCalendar(); |
||
31 | // int month = mc.getMonth(); |
||
32 | // MyCalendar firstYear; |
||
33 | // MyCalendar secondYear; |
||
34 | // if(month <= 9) |
||
35 | // { |
||
36 | // firstYear = new MyCalendar(mc.getYear() - 1,1,1); |
||
37 | // secondYear = new MyCalendar(mc.getYear(),1,1); |
||
38 | // } |
||
39 | // else |
||
40 | // { |
||
41 | // firstYear = new MyCalendar(mc.getYear(),1,1); |
||
42 | // secondYear = new MyCalendar(mc.getYear()+1,1,1); |
||
43 | // } |
||
44 | // |
||
45 | // String firstYearStr = SIGES_importFirstYearFormat.format(firstYear.getTime()); |
||
46 | // String secondYearStr = SIGES_importSecondYearFormat.format(secondYear.getTime()); |
||
47 | // |
||
48 | // return getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormat); |
||
206 | jmachado | 49 | } |
50 | |||
343 | jmachado | 51 | public static 1.5.0/docs/api/java/lang/String.html">String getSemestre() |
52 | { |
||
53 | MyCalendar mc = new MyCalendar(); |
||
54 | int month = mc.getMonth(); |
||
55 | if((month > 8 && month <=12) || (month >= 1 && month <=2)) |
||
56 | { |
||
57 | return "S1"; |
||
58 | } |
||
59 | else |
||
60 | { |
||
61 | return "S2"; |
||
62 | } |
||
63 | } |
||
64 | |||
371 | jmachado | 65 | public static enum SemestreModerate |
66 | { |
||
67 | S1, |
||
68 | S2, |
||
69 | S1S2 |
||
70 | } |
||
71 | |||
72 | public static SemestreModerate getSemestreModerate() |
||
73 | { |
||
74 | MyCalendar mc = new MyCalendar(); |
||
75 | int month = mc.getMonth(); |
||
76 | if(month > 8 && month <=12) |
||
77 | { |
||
78 | return SemestreModerate.S1; |
||
79 | } |
||
80 | else if(month >= 1 && month <=3) |
||
81 | { |
||
82 | return SemestreModerate.S1S2; |
||
83 | } |
||
84 | else |
||
85 | { |
||
86 | return SemestreModerate.S2; |
||
87 | } |
||
88 | } |
||
89 | |||
214 | jmachado | 90 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYearIntranet() |
206 | jmachado | 91 | { |
214 | jmachado | 92 | MyCalendar mc = new MyCalendar(); |
93 | int month = mc.getMonth(); |
||
94 | MyCalendar firstYear; |
||
95 | MyCalendar secondYear; |
||
96 | if(month <= 8) |
||
97 | { |
||
98 | firstYear = new MyCalendar(mc.getYear() - 1,1,1); |
||
99 | secondYear = new MyCalendar(mc.getYear(),1,1); |
||
100 | } |
||
101 | else |
||
102 | { |
||
103 | firstYear = new MyCalendar(mc.getYear(),1,1); |
||
104 | secondYear = new MyCalendar(mc.getYear()+1,1,1); |
||
105 | } |
||
106 | |||
107 | 1.5.0/docs/api/java/lang/String.html">String firstYearStr = SIGES_importFirstYearFormatIntranet.format(firstYear.getTime()); |
||
108 | 1.5.0/docs/api/java/lang/String.html">String secondYearStr = SIGES_importSecondYearFormatIntranet.format(secondYear.getTime()); |
||
109 | |||
110 | return getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormatIntranet); |
||
111 | } |
||
112 | |||
345 | jmachado | 113 | public static 1.5.0/docs/api/java/lang/String.html">String getImportYearIntranet(1.5.0/docs/api/java/lang/String.html">String importYear) |
114 | { |
||
115 | 1.5.0/docs/api/java/lang/String.html">String decadeStr = importYear.substring(0,2); |
||
116 | if(importYear.substring(4,6).equals("00")) |
||
117 | { |
||
118 | 1.5.0/docs/api/java/lang/String.html">String decade = importYear.substring(0,2); |
||
119 | int nextdecade= 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(decade)+1; |
||
120 | decadeStr = "" + nextdecade; |
||
121 | } |
||
122 | return getFormatedImportYear(importYear.substring(0,4),decadeStr+importYear.substring(4,6),SIGES_importFinalFormatIntranet); |
||
123 | } |
||
124 | |||
214 | jmachado | 125 | 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) |
126 | { |
||
206 | jmachado | 127 | 1.5.0/docs/api/java/lang/String.html">String[] years = {firstYearStr,secondYearStr}; |
214 | jmachado | 128 | return finalFormat.format(years); |
206 | jmachado | 129 | } |
130 | |||
131 | public static List<String> getImportYears(int size) |
||
132 | { |
||
133 | MyCalendar mc = new MyCalendar(); |
||
134 | int month = mc.getMonth(); |
||
135 | MyCalendar firstYear; |
||
136 | MyCalendar secondYear; |
||
137 | if(month <= 8) |
||
138 | { |
||
139 | firstYear = new MyCalendar(mc.getYear() - 1,1,1); |
||
140 | secondYear = new MyCalendar(mc.getYear(),1,1); |
||
141 | } |
||
142 | else |
||
143 | { |
||
144 | firstYear = new MyCalendar(mc.getYear(),1,1); |
||
145 | secondYear = new MyCalendar(mc.getYear()+1,1,1); |
||
146 | } |
||
147 | |||
148 | 1.5.0/docs/api/java/lang/String.html">String firstYearStr = SIGES_importFirstYearFormat.format(firstYear.getTime()); |
||
149 | 1.5.0/docs/api/java/lang/String.html">String secondYearStr = SIGES_importSecondYearFormat.format(secondYear.getTime()); |
||
150 | |||
151 | List<String> importYears = new ArrayList<String>(); |
||
214 | jmachado | 152 | importYears.add(getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormat)); |
206 | jmachado | 153 | |
154 | for(int i = 0; i < size;i++) |
||
155 | { |
||
156 | firstYear = new MyCalendar(firstYear.getYear() - 1,1,1); |
||
157 | secondYear = new MyCalendar(secondYear.getYear() - 1,1,1); |
||
158 | firstYearStr = SIGES_importFirstYearFormat.format(firstYear.getTime()); |
||
159 | secondYearStr = SIGES_importSecondYearFormat.format(secondYear.getTime()); |
||
214 | jmachado | 160 | importYears.add(getFormatedImportYear(firstYearStr,secondYearStr,SIGES_importFinalFormat)); |
206 | jmachado | 161 | } |
162 | return importYears; |
||
163 | } |
||
164 | |||
215 | jmachado | 165 | public static List<String> getYears(int size) |
166 | { |
||
167 | List<String> years = new ArrayList<String>(); |
||
168 | MyCalendar c = new MyCalendar(); |
||
169 | for(int i = c.getYear(); i > c.getYear() - size;i-- ) |
||
170 | years.add("" + i); |
||
171 | return years; |
||
172 | } |
||
173 | |||
206 | jmachado | 174 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) |
175 | { |
||
176 | 1.5.0/docs/api/java/lang/System.html">System.out.println(getImportYears(10)); |
||
177 | } |
||
178 | } |