def testSpeed(): import time from time import strftime #format = 'Date: %Y/%m/%d - Time: %H:%M:%S - %a %A %C %B %b %g %G %V' format = '%Y/%m/%d - %H:%M:%S' format2 = '%OY/%Om/%Od - %OH:%OM:%OS' n = 1 ######## binFmt = compileTmFormat(format) mode = core.DATE_GREG tm = list(time.localtime()) jd = to_jd(tm[0], tm[1], tm[2], mode) ######## t0 = now() for i in range(n): strftime(format, tm) t1 = now() print('Python strftime: %s sec'%(t1-t0)) ######## jd = to_jd(tm[0], tm[1], tm[2], mode) t0 = now() for i in range(n): formatTime(binFmt, mode, jd, tm) t1 = now() print('My strftime: %s sec'%(t1-t0)) ######## from scal2.ui_gtk.preferences import strftime t0 = now() for i in range(n): strftime(format2, tm) t1 = now() print('My old strftime: %s sec'%(t1-t0))
def testSpeed(): import time from time import strftime #format = 'Date: %Y/%m/%d - Time: %H:%M:%S - %a %A %C %B %b %g %G %V' format = '%Y/%m/%d - %H:%M:%S' format2 = '%OY/%Om/%Od - %OH:%OM:%OS' n = 1 ######## binFmt = compileTmFormat(format) mode = core.DATE_GREG tm = list(time.localtime()) jd = to_jd(tm[0], tm[1], tm[2], mode) ######## t0 = now() for i in range(n): strftime(format, tm) t1 = now() print('Python strftime: %s sec' % (t1 - t0)) ######## jd = to_jd(tm[0], tm[1], tm[2], mode) t0 = now() for i in range(n): formatTime(binFmt, mode, jd, tm) t1 = now() print('My strftime: %s sec' % (t1 - t0)) ######## from scal2.ui_gtk.preferences import strftime t0 = now() for i in range(n): strftime(format2, tm) t1 = now() print('My old strftime: %s sec' % (t1 - t0))
def convertAllPluginsToIcs(startYear, endYear): startJd = to_jd(startYear, 1, 1, DATE_GREG) endJd = to_jd(endYear+1, 1, 1, DATE_GREG) namePostfix = '-%d-%d'%(startYear, endYear) for plug in core.allPlugList: if isinstance(plug, HolidayPlugin): convertHolidayPlugToIcs(plug, startJd, endJd, namePostfix) elif isinstance(plug, BuiltinTextPlugin): convertBuiltinTextPlugToIcs(plug, startJd, endJd, namePostfix) else: print 'Ignoring unsupported plugin %s'%plug.path
def ymdRange(date1, date2, mode=None): y1, m1, d1 = date1 y2, m2, d2 = date2 if y1==y2 and m1==m2: for d in range(d1, d2): yield y1, m1, d if mode==None: mode = DATE_GREG j1 = int(to_jd(y1, m1, d1, mode)) j2 = int(to_jd(y2, m2, d2, mode)) for j in range(j1, j2): yield jd_to(j, mode)
def updateEndDates(self): y, m, d = self.startDateInput.get_value() jd0 = to_jd(y, m, d, self.altMode) - 1 for row in self.trees: mLen = row[3] jd0 += mLen row[4] = dateLocale(*jd_to(jd0, self.altMode))
def get_epoch(self, mode): from scal2.time_utils import getEpochFromJhms date, hms = self.get_value() return getEpochFromJhms( to_jd(date[0], date[1], date[2], mode), *hms )
def testOutput(): from time import strftime binFmt = compileTmFormat('%Y/%m/%d') year = 2010 month = 1 day = 4 jd = to_jd(year, month, day, core.DATE_GREG) tm = (year, month, day, 12, 10, 0, 15, 1, 1) print(formatTime(binFmt, core.DATE_GREG, jd, tm)) print(strftime('%OY/%Om/%Od', tm))
def updateVars(self): y, m, d = self.startDateInput.get_value() monthDb.endJd = monthDb.startJd = to_jd(y, m, d, self.altMode) monthDb.monthLenByYm = {} for row in self.trees: ym = row[0] mLen = row[3] monthDb.monthLenByYm[ym] = mLen monthDb.endJd += mLen monthDb.save()
def prepareToday(): tm = getCurrentTime() y, m, d = localtime(tm)[:3] #log.debug('Date: %s/%s/%s Epoch: %s'%(y, m, d, tm)) todayJd = to_jd(y, m, d, DATE_GREG) dayRemainSecondsCeil = int(-(tm - 1)%(24*3600)) timeout_add_seconds(dayRemainSecondsCeil, prepareToday) for group in eventGroups: if not group.enable: continue for epoch0, epoch1, eid in group.occur.search(getEpochFromJd(todayJd), getEpochFromJd(todayJd+1)): event = group[eid] if not event.notifiers: continue dt = epoch0 - event.getNotifyBeforeSec() - tm if dt >= 0: timeout_add_seconds(int(dt)+1, notify, eid)
def get_epoch(self, mode): from scal2.time_utils import getEpochFromJhms date, hms = self.get_value() return getEpochFromJhms(to_jd(date[0], date[1], date[2], mode), *hms)
def weekNumberMonday(a): jd0 = to_jd(cell.dates[mode][0], 1, 1, mode) return _((cell.jd - jd0 + jd0%7) / 7, fillZero=2)
def compileTmFormat(format, hasTime=True): ## format: 'Today: %Y/%m/%d' ## pyFmt: 'Today: %s/%s/%s' ## funcs: (get_y, get_m, get_d) pyFmt = '' funcs = [] n = len(format) i = 0 while i < n: c0 = format[i] if c0 != '%': pyFmt += c0 i += 1 continue if i == n - 1: pyFmt += c0 break c1 = format[i + 1] if c1 == '%': pyFmt += '%' i += 2 continue if c1 == 'Y': funcs.append( lambda cell, mode, tm: _(cell.dates[mode][0], fillZero=4)) pyFmt += '%s' i += 2 continue elif c1 == 'y': funcs.append(lambda cell, mode, tm: _(cell.dates[mode][0] % 100, fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'm': funcs.append( lambda cell, mode, tm: _(cell.dates[mode][1], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'd': funcs.append( lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'Q': ## calendar name (gregorian, jalali, ...) funcs.append(lambda cell, mode, tm: _(calTypes[mode].name)) pyFmt += '%s' i += 2 continue elif c1 == 'a': funcs.append( lambda cell, mode, tm: core.weekDayNameAb[cell.weekDay]) pyFmt += '%s' i += 2 continue elif c1 == 'A': funcs.append(lambda cell, mode, tm: core.weekDayName[cell.weekDay]) pyFmt += '%s' i += 2 continue elif c1 == 'b' or c1 == 'h': ## ?????????? funcs.append(lambda cell, mode, tm: _(calTypes[ mode].getMonthNameAb(cell.dates[mode][1]))) pyFmt += '%s' i += 2 continue elif c1 == 'B': funcs.append(lambda cell, mode, tm: _(calTypes[mode].getMonthName( cell.dates[mode][1]))) pyFmt += '%s' i += 2 continue #elif c1=='c':## ????? locale's date and time (e.g., Thu Mar 3 23:05:25 2005) #elif c1=='x':## ????? locale's date representation (e.g., 12/31/99) elif c1 == 'C': funcs.append(lambda cell, mode, tm: _(cell.dates[mode][0] // 100, fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'D': ## %m/%d/%y funcs += [ lambda cell, mode, tm: _(cell.dates[mode][1], fillZero=2), lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2), lambda cell, mode, tm: _(cell.dates[mode][0] % 100, fillZero=2) ] pyFmt += '%s/%s/%s' i += 2 continue elif c1 == 'e': ## day of month, space padded; same as %_d funcs.append( lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2)) pyFmt += '%2s' i += 2 continue elif c1 == 'F': ## %Y-%m-%d funcs += [ lambda cell, mode, tm: _(cell.dates[mode][0], fillZero=4), lambda cell, mode, tm: _(cell.dates[mode][1], fillZero=2), lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2) ] pyFmt += '%s-%s-%s' i += 2 continue elif c1 == 'g': ## not affected by mode! funcs.append( lambda cell, mode, tm: _(isow_year(cell.jd) % 100, fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'G': ## not affected by mode! funcs.append( lambda cell, mode, tm: _(isow_year(cell.jd), fillZero=4)) pyFmt += '%s' i += 2 continue elif c1 == 'V': ## not affected by mode! funcs.append(lambda cell, mode, tm: _(isow(cell.jd), fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'u': funcs.append(lambda cell, mode, tm: _(cell.jd % 7 + 1)) pyFmt += '%s' i += 2 continue elif c1 == 'w': funcs.append(lambda cell, mode, tm: _((cell.jd + 1) % 7)) ## jwday pyFmt += '%s' i += 2 continue elif c1 == 'W': def weekNumberMonday(cell, mode, tm): jd0 = to_jd(cell.dates[mode][0], 1, 1, mode) return _((cell.jd - jd0 + jd0 % 7) // 7, fillZero=2) funcs.append(weekNumberMonday) pyFmt += '%s' i += 2 continue #elif c1=='U':##???????????????????????????????????????? # funcs.append(lambda cell, mode, tm: _()) # pyFmt += '%s' # i += 2 # continue elif c1 == 'j': funcs.append(lambda cell, mode, tm: _(cell.jd - to_jd( cell.dates[mode][0], 1, 1, mode) + 1, fillZero=3)) pyFmt += '%s' i += 2 continue elif c1 == 'n': pyFmt += '\n' i += 2 continue elif c1 == 't': pyFmt += '\t' i += 2 continue elif c1 == 'z': def tz(cell, mode, tm): m = int(getUtcOffsetByGDate(*cell.dates[core.DATE_GREG]) / 60) return _(m // 60, fillZero=2) + _(m % 60, fillZero=2) funcs.append(tz) pyFmt += '%s' i += 2 continue #elif c1=='Z': ##alphabetic time zone abbreviation (e.g., EDT) elif c1 == ':': c2 = format[i + 2] if c2 == 'z': ## %:z def tz(cell, mode, tm): m = int( getUtcOffsetByGDate(*cell.dates[core.DATE_GREG]) / 60) return _(m // 60, fillZero=2) + ':' + _(m % 60, fillZero=2) funcs.append(tz) pyFmt += '%s' i += 3 continue ## %::z , %:::z #elif c2==':':## ??????????????????????? elif hasTime: if c1 == 'H': funcs.append(lambda cell, mode, tm: _(tm[0], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'I': funcs.append(lambda cell, mode, tm: _( (tm[0] - 1) % 12 + 1, fillZero=2)) ## ???????? pyFmt += '%s' i += 2 continue elif c1 == 'k': funcs.append(lambda cell, mode, tm: _(tm[0])) pyFmt += '%s' i += 2 continue elif c1 == 'l': funcs.append(lambda cell, mode, tm: _( (tm[0] - 1) % 12 + 1)) ## ???????? pyFmt += '%s' i += 2 continue elif c1 == 'r': ## %I:%M:%s PM funcs.append(lambda cell, mode, tm: \ _((tm[0]-1)%12+1, fillZero=2) + ':' +\ _(tm[1], fillZero=2) + ':' +\ _(tm[2], fillZero=2) + ' ' +\ _('AM' if tm[0]<12 else 'PM') ) pyFmt += '%s' i += 2 continue elif c1 == 'R': ## %H:%M funcs.append(lambda cell, mode, tm: \ _(tm[0], fillZero=2) + ':' +\ _(tm[1], fillZero=2) ) pyFmt += '%s' i += 2 continue elif c1 == 'M': funcs.append(lambda cell, mode, tm: _(tm[1], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 'S': funcs.append(lambda cell, mode, tm: _(int(tm[2]), fillZero=2)) pyFmt += '%s' i += 2 continue elif c1 == 's': ## seconds since 1970-01-01 00:00:00 UTC #funcs.append(lambda cell, mode, tm: _(int(time.mktime(a[2:7]+(int(tm[2]), 0, 0, 1))))) funcs.append(lambda cell, mode, tm: _( core.getEpochFromJhms(cell.jd, *tm))) pyFmt += '%s' i += 2 continue elif c1 == 'N': funcs.append(lambda cell, mode, tm: _( int(tm[2] * 1000000000 % 1000000000))) pyFmt += '%s' i += 2 continue elif c1 == 'p': funcs.append(lambda cell, mode, tm: _('AM' if tm[0] < 12 else 'PM')) pyFmt += '%s' i += 2 continue elif c1 == 'P': funcs.append(lambda cell, mode, tm: _('AM' if tm[0] < 12 else 'PM').lower()) pyFmt += '%s' i += 2 continue elif c1 == 'T': ## %%H:%M:%S funcs.append(lambda cell, mode, tm: \ _(tm[0], fillZero=2) + ':' +\ _(tm[1], fillZero=2) + ':' +\ _(tm[2], fillZero=2) ) pyFmt += '%s' i += 2 continue elif c1 == 'X': ## locale's time representation (e.g., 23:13:48) funcs.append(lambda cell, mode, tm: \ _(tm[0], fillZero=2) + ':' +\ _(tm[1], fillZero=2) + ':' +\ _(tm[2], fillZero=2) ) pyFmt += '%s' i += 2 continue pyFmt += ('%' + c1) i += 2 return (pyFmt, funcs) ## binFmt
def getCurrentJd():## time() and mktime(localtime()) both return GMT, not local y, m, d = localtime()[:3] return to_jd(y, m, d, DATE_GREG)
######################################################### def restart():## will not return from function os.environ['LANG'] = locale_man.sysLangDefault restartLow() ######################################################### def ymdRange((y1, m1, d1), (y2, m2, d2), mode=None): if y1==y2 and m1==m2: for d in range(d1, d2): yield y1, m1, d if mode==None: mode = DATE_GREG j1 = int(to_jd(y1, m1, d1, mode)) j2 = int(to_jd(y2, m2, d2, mode)) for j in range(j1, j2): yield jd_to(j, mode) def getSysDate(mode=None): if mode is None: mode = primaryMode if mode==DATE_GREG: return localtime()[:3] else: gy, gm, gd = localtime()[:3] return convert(gy, gm, gd, DATE_GREG, mode) def mylocaltime(sec=None, mode=None): if mode==None:##DATE_GREG
def getJdRangeForMonth(year, month, mode): day = getMonthLen(year, month, mode) return ( to_jd(year, month, 1, mode), to_jd(year, month, day, mode) + 1, )
date[0] *= -1 checkDate(date) return date def validDate(mode, y, m, d): ## move to cal-modules if y < 0: return False if m < 1 or m > 12: return False if d > getMonthLen(y, m, mode): return False return True datesDiff = lambda y1, m1, d1, y2, m2, d2: to_jd( calType.primary, y2, m2, d2) - to_jd(calType.primary, y1, m1, d1) dayOfYear = lambda y, m, d: datesDiff(y, 1, 1, y, m, d) + 1 ## jwday: Calculate day of week from Julian day ## 0 = Sunday ## 1 = Monday jwday = lambda jd: (jd + 1) % 7 def getJdRangeForMonth(year, month, mode): day = getMonthLen(year, month, mode) return ( to_jd(year, month, 1, mode), to_jd(year, month, day, mode) + 1, )
def get_epoch(self, mode): date, hms = self.get_value() return getEpochFromJhms( to_jd(date[0], date[1], date[2], mode), *hms )
dayOfYear = lambda y, m, d: datesDiff(y, 1, 1, y, m, d) + 1 ## jwday: Calculate day of week from Julian day ## 0 = Sunday ## 1 = Monday jwday = lambda jd: (jd + 1) % 7 def getJdRangeForMonth(year, month, mode): day = getMonthLen(year, month, mode) return ( to_jd(year, month, 1, mode), to_jd(year, month, day, mode) + 1, ) def getFloatYearFromEpoch(epoch, mode): module = calTypes[mode] return float(epoch - module.epoch)/module.avgYearLen + 1 def getEpochFromFloatYear(year, mode): module = calTypes[mode] return module.epoch + (year-1)*module.avgYearLen getFloatYearFromJd = lambda jd, mode: getFloatYearFromEpoch(getEpochFromJd(jd), mode) getJdFromFloatYear = lambda year, mode: getJdFromEpoch(getEpochFromFloatYear(year, mode)) getEpochFromDate = lambda y, m, d, mode: getEpochFromJd(to_jd(y, m, d, mode))
if neg: date[0] *= -1 checkDate(date) return date def validDate(mode, y, m, d):## move to cal-modules if y<0: return False if m<1 or m>12: return False if d > getMonthLen(y, m, mode): return False return True datesDiff = lambda y1, m1, d1, y2, m2, d2: to_jd(calType.primary, y2, m2, d2) - to_jd(calType.primary, y1, m1, d1) dayOfYear = lambda y, m, d: datesDiff(y, 1, 1, y, m, d) + 1 ## jwday: Calculate day of week from Julian day ## 0 = Sunday ## 1 = Monday jwday = lambda jd: (jd + 1) % 7 def getJdRangeForMonth(year, month, mode): day = getMonthLen(year, month, mode) return ( to_jd(year, month, 1, mode), to_jd(year, month, day, mode) + 1, )
def getJdByIcsDate(dateStr): tm = strptime(dateStr, '%Y%m%d') return to_jd(tm.tm_year, tm.tm_mon, tm.tm_mday, DATE_GREG)
def compileTmFormat(format, hasTime=True): ## format: 'Today: %Y/%m/%d' ## pyFmt: 'Today: %s/%s/%s' ## funcs: (get_y, get_m, get_d) pyFmt = '' funcs = [] n = len(format) i = 0 while i<n: c0 = format[i] if c0!='%': pyFmt += c0 i += 1 continue if i==n-1: pyFmt += c0 break c1 = format[i+1] if c1=='%': pyFmt += '%' i += 2 continue if c1=='Y': funcs.append(lambda cell, mode, tm: _(cell.dates[mode][0], fillZero=4)) pyFmt += '%s' i += 2 continue elif c1=='y': funcs.append(lambda cell, mode, tm: _(cell.dates[mode][0]%100, fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='m': funcs.append(lambda cell, mode, tm: _(cell.dates[mode][1], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='d': funcs.append(lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='Q':## calendar name (gregorian, jalali, ...) funcs.append(lambda cell, mode, tm: _(calTypes[mode].name)) pyFmt += '%s' i += 2 continue elif c1=='a': funcs.append(lambda cell, mode, tm: core.weekDayNameAb[cell.weekDay]) pyFmt += '%s' i += 2 continue elif c1=='A': funcs.append(lambda cell, mode, tm: core.weekDayName[cell.weekDay]) pyFmt += '%s' i += 2 continue elif c1=='b' or c1=='h':## ?????????? funcs.append(lambda cell, mode, tm: _(calTypes[mode].getMonthNameAb(cell.dates[mode][1]))) pyFmt += '%s' i += 2 continue elif c1=='B': funcs.append(lambda cell, mode, tm: _(calTypes[mode].getMonthName(cell.dates[mode][1]))) pyFmt += '%s' i += 2 continue #elif c1=='c':## ????? locale's date and time (e.g., Thu Mar 3 23:05:25 2005) #elif c1=='x':## ????? locale's date representation (e.g., 12/31/99) elif c1=='C': funcs.append(lambda cell, mode, tm: _(cell.dates[mode][0]//100, fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='D':## %m/%d/%y funcs += [ lambda cell, mode, tm: _(cell.dates[mode][1], fillZero=2), lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2), lambda cell, mode, tm: _(cell.dates[mode][0]%100, fillZero=2) ] pyFmt += '%s/%s/%s' i += 2 continue elif c1=='e':## day of month, space padded; same as %_d funcs.append(lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2)) pyFmt += '%2s' i += 2 continue elif c1=='F':## %Y-%m-%d funcs += [ lambda cell, mode, tm: _(cell.dates[mode][0], fillZero=4), lambda cell, mode, tm: _(cell.dates[mode][1], fillZero=2), lambda cell, mode, tm: _(cell.dates[mode][2], fillZero=2) ] pyFmt += '%s-%s-%s' i += 2 continue elif c1=='g':## not affected by mode! funcs.append(lambda cell, mode, tm: _(isow_year(cell.jd)%100, fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='G':## not affected by mode! funcs.append(lambda cell, mode, tm: _(isow_year(cell.jd), fillZero=4)) pyFmt += '%s' i += 2 continue elif c1=='V':## not affected by mode! funcs.append(lambda cell, mode, tm: _(isow(cell.jd), fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='u': funcs.append(lambda cell, mode, tm: _(cell.jd%7 + 1)) pyFmt += '%s' i += 2 continue elif c1=='w': funcs.append(lambda cell, mode, tm: _((cell.jd+1)%7)) ## jwday pyFmt += '%s' i += 2 continue elif c1=='W': def weekNumberMonday(a): jd0 = to_jd(cell.dates[mode][0], 1, 1, mode) return _((cell.jd - jd0 + jd0%7) / 7, fillZero=2) funcs.append(weekNumberMonday) pyFmt += '%s' i += 2 continue #elif c1=='U':##???????????????????????????????????????? # funcs.append(lambda cell, mode, tm: _()) # pyFmt += '%s' # i += 2 # continue elif c1=='j': funcs.append(lambda cell, mode, tm: _( cell.jd - to_jd(cell.dates[mode][0], 1, 1, mode) + 1, fillZero=3 )) pyFmt += '%s' i += 2 continue elif c1=='n': pyFmt += '\n' i += 2 continue elif c1=='t': pyFmt += '\t' i += 2 continue elif c1=='z': def tz(a): m = int(getUtcOffsetByDateSec(cell.dates[mode][0], cell.dates[mode][1], cell.dates[mode][2])/60) return _(m//60, fillZero=2) + _(m%60, fillZero=2) funcs.append(tz) pyFmt += '%s' i += 2 continue #elif c1=='Z': ##alphabetic time zone abbreviation (e.g., EDT) elif c1==':': c2 = format[i+2] if c2=='z':## %:z def tz(a): s = int(getUtcOffsetByDateSec(cell.dates[mode][0], cell.dates[mode][1], cell.dates[mode][2])) return _(m//60, fillZero=2) + ':' + _(m%60, fillZero=2) funcs.append(tz) pyFmt += '%s' i += 3 continue ## %::z , %:::z #elif c2==':':## ??????????????????????? elif hasTime: if c1=='H': funcs.append(lambda cell, mode, tm: _(tm[0], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='I': funcs.append(lambda cell, mode, tm: _((tm[0]-1)%12+1, fillZero=2)) ## ???????? pyFmt += '%s' i += 2 continue elif c1=='k': funcs.append(lambda cell, mode, tm: _(tm[0])) pyFmt += '%s' i += 2 continue elif c1=='l': funcs.append(lambda cell, mode, tm: _((tm[0]-1)%12+1)) ## ???????? pyFmt += '%s' i += 2 continue elif c1=='r':## %I:%M:%s PM funcs.append(lambda cell, mode, tm: \ _((tm[0]-1)%12+1, fillZero=2) + ':' +\ _(tm[1], fillZero=2) + ':' +\ _(tm[2], fillZero=2) + ' ' +\ _('AM' if tm[0]<12 else 'PM') ) pyFmt += '%s' i += 2 continue elif c1=='R':## %H:%M funcs.append(lambda cell, mode, tm: \ _(tm[0], fillZero=2) + ':' +\ _(tm[1], fillZero=2) ) pyFmt += '%s' i += 2 continue elif c1=='M': funcs.append(lambda cell, mode, tm: _(tm[1], fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='S': funcs.append(lambda cell, mode, tm: _(int(tm[2]), fillZero=2)) pyFmt += '%s' i += 2 continue elif c1=='s':## seconds since 1970-01-01 00:00:00 UTC #funcs.append(lambda cell, mode, tm: _(int(time.mktime(a[2:7]+(int(tm[2]), 0, 0, 1))))) funcs.append(lambda cell, mode, tm: _(core.getEpochFromJhms(cell.jd, *tm))) pyFmt += '%s' i += 2 continue elif c1=='N': funcs.append(lambda cell, mode, tm: _(int(tm[2]*1000000000%1000000000))) pyFmt += '%s' i += 2 continue elif c1=='p': funcs.append(lambda cell, mode, tm: _('AM' if tm[0]<12 else 'PM')) pyFmt += '%s' i += 2 continue elif c1=='P': funcs.append(lambda cell, mode, tm: _('AM' if tm[0]<12 else 'PM').lower()) pyFmt += '%s' i += 2 continue elif c1=='T':## %%H:%M:%S funcs.append(lambda cell, mode, tm: \ _(tm[0], fillZero=2) + ':' +\ _(tm[1], fillZero=2) + ':' +\ _(tm[2], fillZero=2) ) pyFmt += '%s' i += 2 continue elif c1=='X':## locale's time representation (e.g., 23:13:48) funcs.append(lambda cell, mode, tm: \ _(tm[0], fillZero=2) + ':' +\ _(tm[1], fillZero=2) + ':' +\ _(tm[2], fillZero=2) ) pyFmt += '%s' i += 2 continue pyFmt += ('%'+c1) i += 2 return (pyFmt, funcs) ## binFmt
def get_jd(self, mode): y, m, d = self.get_value() return to_jd(y, m, d, mode)
def weekNumberMonday(cell, mode, tm): jd0 = to_jd(cell.dates[mode][0], 1, 1, mode) return _((cell.jd - jd0 + jd0 % 7) // 7, fillZero=2)