def weekcalendar(self): '''Returns (year, week, weekday)''' year, week, weekday = weekcalendar(self) if weekday == 1 and self.isoweekday() == 7: weekday = 0 # See module doc on weekday else: weekday = self.isoweekday() return year, week, weekday
def path_from_date(self, date): '''Returns the path for a calendar page for a specific date''' if self.preferences['granularity'] == DAY: path = date.strftime('%Y:%m:%d') elif self.preferences['granularity'] == WEEK: year, week, day = weekcalendar(date) path = '%i:Week %02i' % (year, week) elif self.preferences['granularity'] == MONTH: path = date.strftime('%Y:%m') elif self.preferences['granularity'] == YEAR: path = date.strftime('%Y') return Path( self.preferences['namespace'] + ':' + path )
def path_from_date(self, date): '''Returns the path for a calendar page for a specific date''' if self.preferences['granularity'] == DAY: path = date.strftime('%Y:%m:%d') elif self.preferences['granularity'] == WEEK: year, week, day = weekcalendar(date) path = '%i:Week %02i' % (year, week) elif self.preferences['granularity'] == MONTH: path = date.strftime('%Y:%m') elif self.preferences['granularity'] == YEAR: path = date.strftime('%Y') return self.preferences['namespace'].child(path)
def runTest(self): # now() dt = datetime.now() s = dt.isoformat() self.assertTrue(isinstance(s, str) and len(s) > 0) s = dt.strftime("%z") self.assertTrue(isinstance(s, str) and len(s) > 0) s = dt.strftime("%Z") self.assertTrue(isinstance(s, str) and len(s) > 0) # strftime s = datetime.strftime('%a', dt) self.assertTrue(isinstance(s, str) and len(s) > 0) s = datetime.strftime('%%', dt) self.assertEqual(s, '%') # Failed under msys python3.7.2 #s = datetime.strftime('%u', dt) #self.assertTrue(isinstance(s, str) and len(s) > 0) #s = datetime.strftime('%V', dt) #self.assertTrue(isinstance(s, str) and len(s) > 0) # strfcal s = datetime.strfcal('%w', dt) self.assertTrue(isinstance(s, str) and len(s) > 0) s = datetime.strfcal('%W', dt) self.assertTrue(isinstance(s, str) and len(s) > 0) s = datetime.strfcal('%Y', dt) self.assertTrue(isinstance(s, str) and len(s) > 0) s = datetime.strfcal('%%', dt) self.assertEqual(s, '%') # weekcalendar year, week, weekday = datetime.weekcalendar(dt) self.assertTrue(isinstance(year, int) and 1900 < year and 3000 > year) self.assertTrue(isinstance(week, int) and 1 <= week and 53 >= week) self.assertTrue( isinstance(weekday, int) and 1 <= weekday and 7 >= weekday) # dates_for_week start, end = datetime.dates_for_week(year, week) self.assertTrue(isinstance(start, datetime.date)) self.assertTrue(isinstance(end, datetime.date)) self.assertTrue(start <= dt.date() and end >= dt.date())
def runTest(self): # now() dt = datetime.now() s = dt.isoformat() self.assertTrue(isinstance(s, basestring) and len(s) > 0) s = dt.strftime("%z") self.assertTrue(isinstance(s, basestring) and len(s) > 0) s = dt.strftime("%Z") self.assertTrue(isinstance(s, basestring) and len(s) > 0) # strftime s = datetime.strftime('%a', dt) self.assertTrue(isinstance(s, basestring) and len(s) > 0) s = datetime.strftime('%%', dt) self.assertEqual(s, '%') s = datetime.strftime('%u', dt) self.assertTrue(isinstance(s, basestring) and len(s) > 0) s = datetime.strftime('%V', dt) self.assertTrue(isinstance(s, basestring) and len(s) > 0) # strfcal s = datetime.strfcal('%w', dt) self.assertTrue(isinstance(s, basestring) and len(s) > 0) s = datetime.strfcal('%W', dt) self.assertTrue(isinstance(s, basestring) and len(s) > 0) s = datetime.strfcal('%Y', dt) self.assertTrue(isinstance(s, basestring) and len(s) > 0) s = datetime.strfcal('%%', dt) self.assertEqual(s, '%') # weekcalendar year, week, weekday = datetime.weekcalendar(dt) self.assertTrue(isinstance(year, int) and 1900 < year and 3000 > year) self.assertTrue(isinstance(week, int) and 1 <= week and 53 >= week) self.assertTrue(isinstance(weekday, int) and 1 <= weekday and 7 >= weekday) # dates_for_week start, end = datetime.dates_for_week(year, week) self.assertTrue(isinstance(start, datetime.date)) self.assertTrue(isinstance(end, datetime.date)) self.assertTrue(start <= dt.date() and end >= dt.date())
def path_from_date(self, notebook, date): '''Returns the path for a journal page for a specific date''' properties = self.notebook_properties(notebook) granularity = properties['granularity'] if granularity == DAY: path = date.strftime('%Y:%m:%d') elif granularity == WEEK: year, week, day = weekcalendar(date) path = '%i:Week %02i' % (year, week) elif granularity == MONTH: path = date.strftime('%Y:%m') elif granularity == YEAR: path = date.strftime('%Y') return properties['namespace'].child(path)