def exportToIcs(self, fileName, startJd, endJd): currentTimeStamp = strftime(icsTmFormat) icsText = icsHeader for jd in range(startJd, endJd): isHoliday = False for mode in self.holidays.keys(): (myear, mmonth, mday) = jd_to(jd, mode) if (mmonth, mday) in self.holidays[mode]: isHoliday = True break if isHoliday: (gyear, gmonth, gday) = jd_to(jd, DATE_GREG) (gyear_next, gmonth_next, gday_next) = jd_to(jd+1, DATE_GREG) ####### icsText += 'BEGIN:VEVENT\n' icsText += 'CREATED:%s\n'%currentTimeStamp icsText += 'LAST-MODIFIED:%s\n'%currentTimeStamp icsText += 'DTSTART;VALUE=DATE:%.4d%.2d%.2d\n'%(gyear, gmonth, gday) icsText += 'DTEND;VALUE=DATE:%.4d%.2d%.2d\n'%(gyear_next, gmonth_next, gday_next) icsText += 'CATEGORIES:Holidays\n' icsText += 'TRANSP:TRANSPARENT\n' ## TRANSPARENT because being in holiday time, does not make you busy! ## see http://www.kanzaki.com/docs/ical/transp.html icsText += 'SUMMARY:%s\n'%_('Holiday') icsText += 'END:VEVENT\n' icsText += 'END:VCALENDAR\n' open(fileName, 'w').write(icsText)
def updateWidget(self): ## FIXME common.EventWidget.updateWidget(self) mode = self.event.mode ### startJd = self.event.getJd() self.startDateInput.set_value(jd_to(startJd, mode)) ### (endType, endValue) = self.event.getEnd() if endType == "duration": self.endTypeCombo.set_active(0) self.durationSpin.set_value(endValue) self.endDateInput.set_value(jd_to(self.event.getEndJd(), mode)) ## FIXME elif endType == "date": self.endTypeCombo.set_active(1) self.endDateInput.set_value(endValue) else: raise RuntimeError self.endTypeComboChanged()
def getWeekNumber(year, month, day, adjustZero=True): jd = primary_to_jd(year, month, day) jd0 = primary_to_jd(year, 1, 1) first = jwday(jd-firstWeekDay) - 1 if weekNumberMode==7: weekNumber = (jd - jd0 + first%7) / 7 + 1 else: weekNumber = (jd - jd0 + first%7) / 7 + (first < weekNumberMode-firstWeekDay) if adjustZero and weekNumber==0: weekNumber = getWeekNumber(*jd_to(jd-7, primaryMode)) + 1 return weekNumber
def exportToIcs(self, fileName, startJd, endJd): currentTimeStamp = strftime(icsTmFormat) self.load() ## FIXME mode = self.mode icsText = icsHeader for jd in range(startJd, endJd): (myear, mmonth, mday) = jd_to(jd, mode) dayText = self.get_text(myear, mmonth, mday) if dayText: (gyear, gmonth, gday) = jd_to(jd, DATE_GREG) (gyear_next, gmonth_next, gday_next) = jd_to(jd+1, DATE_GREG) ####### icsText += 'BEGIN:VEVENT\n' icsText += 'CREATED:%s\n'%currentTimeStamp icsText += 'LAST-MODIFIED:%s\n'%currentTimeStamp icsText += 'DTSTART;VALUE=DATE:%.4d%.2d%.2d\n'%(gyear, gmonth, gday) icsText += 'DTEND;VALUE=DATE:%.4d%.2d%.2d\n'%(gyear_next, gmonth_next, gday_next) icsText += 'SUMMARY:%s\n'%dayText icsText += 'END:VEVENT\n' icsText += 'END:VCALENDAR\n' open(fileName, 'w').write(icsText)
def update_cell(self, c): if not c.holiday: for mode in self.holidays.keys():## .keys() in not neccesery (y, m, d) = c.dates[mode] for (hm, hd) in self.holidays[mode]: if m==hm: if d==hd: c.holiday = True break elif d==hd-1 and hd>=modules[mode].minMonthLen: (ny, nm, nd) = jd_to(c.jd+1, mode) if nm>m or ny>y: c.holiday = True break
def update_cell(self, c): (y, m, d) = c.dates[self.mode] text = '' t = self.get_text(y, m, d) if t!='': text += t if self.last_day_merge and d>=modules[self.mode].minMonthLen:## and d<=modules[self.mode].maxMonthLen: (ny, nm, nd) = jd_to(c.jd+1, self.mode) if nm>m or ny>y: nt = self.get_text(y, m, d+1) if nt!='': text += nt if text!='': if c.pluginsText!='': c.pluginsText += '\n' c.pluginsText += text
def floatJdEncode(jd, mode): jd, hour, minute, second = getJhmsFromEpoch(getEpochFromJd(jd)) return dateEncode(jd_to(jd, mode)) + ' ' + timeEncode((hour, minute, second))
getAllPlugListRepr = lambda: '[\n' + '\n'.join([' %r,'%plug for plug in allPlugList]) + '\n]' ######################################################### def ymdRange((y1, m1, d1), (y2, m2, d2), mode=None): if y1==y2 and m1==m2: return [(y1, m1, d) for d in range(d1, d2)] if mode==None: mode=DATE_GREG j1 = int(to_jd(y1, m1, d1, mode)) j2 = int(to_jd(y2, m2, d2, mode)) l = [] for j in range(j1, j2): l.append(jd_to(j, mode)) return l 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 return list(localtime(sec)) t = list(localtime(sec))