diff options
author | David A. Madore <david+git@madore.org> | 2012-02-26 16:22:49 +0100 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2012-02-26 16:22:49 +0100 |
commit | 7f163c200f7da4a91c0d4dee325752018f821dad (patch) | |
tree | d3b29e86f7101788851f60d36ec611d1fcccb6b9 /org | |
parent | 045c56305ad585b037aff655ddbf74490e35e5be (diff) | |
download | damlengine-7f163c200f7da4a91c0d4dee325752018f821dad.tar.gz damlengine-7f163c200f7da4a91c0d4dee325752018f821dad.tar.bz2 damlengine-7f163c200f7da4a91c0d4dee325752018f821dad.zip |
Now check day of week on entries.
Diffstat (limited to 'org')
-rw-r--r-- | org/madore/damlengine/Calendar.java | 76 | ||||
-rw-r--r-- | org/madore/damlengine/TodoEntryElement.java | 16 |
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"); |