summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine
diff options
context:
space:
mode:
Diffstat (limited to 'org/madore/damlengine')
-rw-r--r--org/madore/damlengine/Calendar.java76
-rw-r--r--org/madore/damlengine/TodoEntryElement.java16
2 files changed, 92 insertions, 0 deletions
diff --git a/org/madore/damlengine/Calendar.java b/org/madore/damlengine/Calendar.java
new file mode 100644
index 0000000..d95b602
--- /dev/null
+++ b/org/madore/damlengine/Calendar.java
@@ -0,0 +1,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);
+ }
+
+}
diff --git a/org/madore/damlengine/TodoEntryElement.java b/org/madore/damlengine/TodoEntryElement.java
index de9c60d..d7a2aff 100644
--- a/org/madore/damlengine/TodoEntryElement.java
+++ b/org/madore/damlengine/TodoEntryElement.java
@@ -29,6 +29,7 @@ public final class TodoEntryElement extends TodoDefaultElement {
throw new IllegalArgumentException("entry node can only be child of weblog node");
Element article = ctx.doc.createElementNS(DamlEngine.XHTML_NS, "article");
+ String lang = LangHelper.getLangRec(node);
String explicitLang = LangHelper.getLangNorec(node);
if ( explicitLang != null )
LangHelper.setLangNorec(article, explicitLang);
@@ -45,6 +46,21 @@ public final class TodoEntryElement extends TodoDefaultElement {
String entryMonthStr = entryDateMatcher.group(2);
String entryDayStr = entryDateMatcher.group(3);
String entryDowStr = node.getAttributeNS(null, "day_of_week");
+ {
+ final int entryYear = Integer.parseInt(entryYearStr);
+ final int entryMonth = Integer.parseInt(entryMonthStr);
+ final int entryDay = Integer.parseInt(entryDayStr);
+ final String entryRefDowStr
+ = Calendar.dateDowName(lang, entryYear, entryMonth, entryDay);
+ if ( entryRefDowStr != null ) {
+ if ( entryDowStr.equals("") ) {
+ entryDowStr = entryRefDowStr;
+ } else if ( ( ! entryDowStr.equals(entryRefDowStr) )
+ && node.getAttributeNS(null, "override-day-of-week").equals("") ) {
+ System.err.println("warning: "+entryDateStr+" day of week given "+entryDowStr+" expected "+entryRefDowStr);
+ }
+ }
+ }
String entryCatStr = node.getAttributeNS(null, "cat");
String entryDoSinglePageStr = node.getAttributeNS(null, "single-page");
String entryCdateStr = node.getAttributeNS(null, "cdate");