1. Guido Draheim
  2. trac-userscriptservernotes-plugin

Commits

Guido Draheim  committed 5f0eeff

fix weekday handling

  • Participants
  • Parent commits dfa7fc0
  • Branches trunk

Comments (0)

Files changed (3)

File GNUmakefile

View file
 test unittest check:
 	cd src && $(MAKE) $@
 test_%:        # run a single unittest by giving the function name
-	@ for filename in src/tests/*_test.py ; do : \
+	@ for filename in src/tests/*_test.py ; do echo "$$filename..." \
 	;  class=`basename $$filename .py` \
+	;  echo  "grep 'def $@' $$filename" \
 	;  func1=`grep "def $@" $$filename \
 	    | sed -e "s/.*def  *//" -e "s/[(].*//" -e q` \
+	;  echo "'$$func1'" \
 	;  test -n "$$func1" && break \
 	; done \
-	; if test -n "$check" ; then : \
+	; if test -n "$$func1" ; then : \
 	;   echo "PYTHONPATH=src  \\" \
 	;   echo "python $$filename $$class.$$func1" \
 	;   echo "" \
 	;         PYTHONPATH=src \
 	          python $$filename "$$class.$$func1" \
 	; else : \
-	    echo "not found $@ in src/tests"; exit 1 \
+	;   echo "not found $@ in src/tests"; exit 1 \
 	; fi
 testlist:      # show available unittest function names (for test_%)
 	@ for filename in src/tests/*_test.py ; do : \

File src/tests/parsedate_test.py

View file
         R = str(D)
         logg.info("\n%s | %s", R, check)
         return R
+    def parse_datetime(self, check):
+        D = usernotes.parsedate.parse_datetime(check)
+        if not D:
+            logg.info("\n----NONE---- | %s", check)
+            return D
+        logg.info("\n%s | %s", str(D), check)
+        return D
     def setUp(self):
         usernotes.parsedate.NOW = datetime.datetime(2012,10,10,22,30)
     def test_000_badtime(self):
         R = self.parsedate("Vorgestern, um 20:16")
         E = "201210082016"
         self.assertEqual(E, R)
-    def test_017_Wochentag_um(self):
-        R = self.parsedate("Freitag, um 20:17")
-        E = "201210062017"
-        self.assertEqual(E, R)
-    def test_018_DatumJahr_um(self):
-        R = self.parsedate("20. Oktober 2011, um 20:18")
-        E = "201110202018"
+    def test_017_DatumJahr_um(self):
+        R = self.parsedate("20. Oktober 2011, um 20:17")
+        E = "201110202017"
         self.assertEqual(E, R)
     def test_018_DatumOhne_um(self):
         R = self.parsedate("20. Oktober, um 20:18")
         R = self.parsedate("vor 3 Tagen")
         E = "201210072230"
         self.assertEqual(E, R)
+    def test_040_Wochentag_Montag(self):
+        D = self.parse_datetime("Montag, um 20:11")
+        E = "2012-10-08 20:11:00"
+        self.assertEqual(0, D.weekday())
+        self.assertEqual(E, str(D))
+    def test_041_Wochentag_Dienstag(self):
+        D = self.parse_datetime("Dienstag, um 20:11")
+        E = "2012-10-09 20:11:00"
+        self.assertEqual(1, D.weekday())
+        self.assertEqual(E, str(D))
+    def test_042_Wochentag_Mittwoch(self):
+        D = self.parse_datetime("Mittwoch, um 20:11")
+        E = "2012-10-03 20:11:00"
+        self.assertEqual(2, D.weekday())
+        self.assertEqual(E, str(D))
+    def test_043_Wochentag_Donnerstag(self):
+        D = self.parse_datetime("Donnerstag, um 20:11")
+        E = "2012-10-04 20:11:00"
+        self.assertEqual(3, D.weekday())
+        self.assertEqual(E, str(D))
+    def test_044_Wochentag_Freitag(self):
+        D = self.parse_datetime("Freitag, um 20:11")
+        E = "2012-10-05 20:11:00"
+        self.assertEqual(4, D.weekday())
+        self.assertEqual(E, str(D))
+    def test_045_Wochentag_Samstag(self):
+        D = self.parse_datetime("Samstag, um 20:11")
+        E = "2012-10-06 20:11:00"
+        self.assertEqual(5, D.weekday())
+        self.assertEqual(E, str(D))
+    def test_046_Wochentag_Sonntag(self):
+        D = self.parse_datetime("Sonntag, um 20:11")
+        E = "2012-10-07 20:11:00"
+        self.assertEqual(6, D.weekday())
+        self.assertEqual(E, str(D))
     
 if __name__ == "__main__":
     unittest.main()

File src/usernotes/parsedate.py

View file
     return None
 
 def _WeekdayToNumber(weekday):
-    if weekday == "Sonntag": return 0;
-    if weekday == "Montag": return 1;
-    if weekday == "Dienstag": return 2;
-    if weekday == "Mittwoch": return 3;
-    if weekday == "Donnerstag": return 4;
-    if weekday == "Freitag": return 5;
-    if weekday == "Samstag": return 6;
+    # python datetime.weekday() "Monday is 0 and Sunday is 6."
+    if weekday == "Montag": return 0;
+    if weekday == "Dienstag": return 1;
+    if weekday == "Mittwoch": return 2;
+    if weekday == "Donnerstag": return 3;
+    if weekday == "Freitag": return 4;
+    if weekday == "Samstag": return 5;
+    if weekday == "Sonntag": return 6;
     return -1
 
 def _DaysInMonth(month):
 _E.names = ["%w","%H","%M"]
 _F = _P(r"(\d+)-(\d+)-(\d+)[.T ](\d+):(\d+)")
 _F.names = ["%Y","%m","%d","%H","%M"]
+_V = _P(r"(vor einigen Sekunden)")
+_V.names = ["--"]
 _X = _P(r"(now|jetzt)")
 _X.names = ["--"]
 
 class DatestringFromFormattedDate:
     def __init__(self, value = None):
         self.date = now()
-        self.patterns = [ _A, _B1, _B2, _B3, _C, _C2, _D, _E, _F, _X]
+        self.patterns = [ _A, _B1, _B2, _B3, _C, _C2, _D, _E, _F, _V, _X]
         if value is not None:
             self.parse(value)
     def __str__(self):