1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package org.madore.damlengine;
import java.util.Map;
import java.util.HashMap;
public final class Calendar {
public final static int monthTab[] = {
-59, -28, 0, 31, 61, 92, 122, 153, 184, 214, 245, 275
};
public static long julianDateMarch1(int year) {
return 1721120 + year*365 + year/4 - year/100 + year/400;
}
public static boolean isLeap(int year) {
return (year%4==0) && ((!(year%100==0))||(year%400==0));
}
public static long julianDate(int year, int month, int day) {
return julianDateMarch1(year)
+ monthTab[month-1]
- ((month<=2 && isLeap(year))?1:0)
+ (day-1);
}
public static int dateDowNumber(int year, int month, int day) {
// 0 = Monday ... 6 = Sunday
return (int)((julianDate(year, month, day))%7);
}
public final static String dowNamesEn[] = {
"Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday"
};
public final static String dowNamesFr[] = {
"lundi", "mardi", "mercredi", "jeudi",
"vendredi", "samedi", "dimanche"
};
public final static String dowNamesDe[] = {
"Montag", "Dienstag", "Mittwoch", "Donnerstag",
"Freitag", "Samstag", "Sonntag"
};
public final static String dowNamesIa[] = {
"lunedi", "martedi", "mercuridi", "jovedi",
"venerdi", "saturdi", "dominica"
};
public final static Map<String,String[]> dowNames;
static {
dowNames = new HashMap<String,String[]>();
dowNames.put("en", dowNamesEn);
dowNames.put("fr", dowNamesFr);
dowNames.put("de", dowNamesDe);
dowNames.put("ia", dowNamesIa);
}
public static String dowName(String lang, int dowNumber) {
String[] dowNamesL = dowNames.get(lang);
if ( dowNamesL == null )
return null;
else
return dowNamesL[dowNumber];
}
public static String dateDowName(String lang,
int year, int month, int day) {
int dowNumber = dateDowNumber(year, month, day);
return dowName(lang, dowNumber);
}
}
|