def main(): c = calendar.LocaleTextCalendar(locale="en_US") c.prmonth(2017, 7) print() c = calendar.LocaleTextCalendar(locale="fr_FR") c.prmonth(2017, 7)
def calendar_locale(): try: c = calendar.LocaleTextCalendar(locale='en_US') c.prmonth(2020, 7) print() c = calendar.LocaleTextCalendar(locale='fr_FR') c.prmonth(2020, 8) except: pass return
def run301_03(): """ locales :return: """ cal = calendar.LocaleTextCalendar(locale='en_US') cal.prmonth(2019, 12) print() cal = calendar.LocaleTextCalendar(locale='zh_CN') cal.prmonth(2019, 12)
def __get_calendar(self, locale, fwday): s = self # 實例化適當的日曆類 if locale is None: return calendar.TextCalendar(fwday) else: return calendar.LocaleTextCalendar(fwday, locale)
def get_weekheader(firstweekday): try: mylocale = '.'.join(getlocale(LC_TIME)) except TypeError: mylocale = 'C' _calendar = calendar.LocaleTextCalendar(firstweekday, locale=mylocale) return _calendar.formatweekheader(2)
def __init__(self, firstWeekDay: int = calendar.MONDAY, locale: str = 'de_DE'): self._cal = calendar.LocaleTextCalendar(firstWeekDay, locale) self.today = datetime.date.today() self._monthList = \ ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'] self._dayList = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag','Sonntag'] self._currentMonthName = self._monthList[self.today.month-1]
def date_name(self) -> str: """Returns month name with year.""" p_calendar = calendar.LocaleTextCalendar(locale=('fr', 'UTF-8')) s_return = '{day} {month}'.format(day=self._day, month=p_calendar.formatmonthname( theyear=self._year, themonth=self._month, width=0, withyear=True)) return s_return
def get_calendar_keyboard(year: int, month: int) -> telebot.types.InlineKeyboardMarkup: """ Create inline keyboard for calendar and return it. Calendar will be created for `year` and `month`. """ # TODO: refactor markup = telebot.types.InlineKeyboardMarkup() text_calendar = calendar.LocaleTextCalendar(locale=calendar_locale) # First row - month and year row: List[telebot.types.InlineKeyboardButton] = [] row.append( telebot.types.InlineKeyboardButton(text_calendar.formatmonthname( year, month, 100).strip(), callback_data='ignore')) markup.row(*row) # Second row - week days week_days: List[str] = [ text_calendar.formatweekday(i, 8).strip() for i in range(7) ] row = [] for week_day in week_days: row.append( telebot.types.InlineKeyboardButton(week_day, callback_data='ignore')) markup.row(*row) my_calendar = calendar.monthcalendar(year, month) for week in my_calendar: row = [] for day in week: if day == 0: row.append( telebot.types.InlineKeyboardButton(' ', callback_data='ignore')) else: row.append( telebot.types.InlineKeyboardButton( str(day), callback_data='calendar_day:{}'.format(day))) markup.row(*row) # Last row - Buttons row = [] row.append( telebot.types.InlineKeyboardButton('<', callback_data='previous_month')) row.append(telebot.types.InlineKeyboardButton(' ', callback_data='ignore')) row.append( telebot.types.InlineKeyboardButton('>', callback_data='next_month')) markup.row(*row) return markup
def test_localecalendars(self): # ensure that Locale{Text,HTML}Calendar resets the locale properly # (it is still not thread-safe though) old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) try: calendar.LocaleTextCalendar(locale='').formatmonthname(2010, 10, 10) except locale.Error: # cannot set the system default locale -- skip rest of test return calendar.LocaleHTMLCalendar(locale='').formatmonthname(2010, 10) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEquals(old_october, new_october)
def meetup_day(year, month, dayOfWeek, dateOffset): cal = calendar.LocaleTextCalendar(locale='en_US') weeks = cal.monthdayscalendar(year, month) days = {"Monday":0, "Tuesday":1, "Wednesday":2, "Thursday":3, \ "Friday":4, "Saturday":5, "Sunday":6} weekValues = {"1st":0, "2nd":1, "3rd":2, "4th":3, "5th":4, \ "teenth":-2, "last":-1} dayIndex = days.get(dayOfWeek) weekOffset = weekValues.get(dateOffset) day = find_day_in_month(weeks, dayIndex, weekOffset) return date(year, month, day)
def obtenerCalendarioMesSiguiente(self): if (self.mesSiguiente == 1): anioSiguiente = self.anio + 1 else: anioSiguiente = self.anio calendario = calendar.LocaleTextCalendar(locale='es_ES') mesSiguiente = calendario.monthdayscalendar(anioSiguiente, self.mesSiguiente) return mesSiguiente
def obtenerCalendarioMesAnterior(self): if (self.mesAnterior == 12): anioAnterior = self.anio - 1 else: anioAnterior = self.anio calendario = calendar.LocaleTextCalendar(locale='es_ES') mesAnterior = calendario.monthdayscalendar(anioAnterior, self.mesAnterior) return mesAnterior
def step_3(): a = calendar.LocaleTextCalendar(locale='russian_Russia') cal= Calendar(root, selectmode="day",) cal.grid(row=3, column=2, pady=0) def grab_date(): my_label.config(text=cal.get_date()) step=3 var=cal.get_date() counter_click(step,var) my_button= Button(root, text="далее",command=lambda: [grab_date(), my_button.grid_remove(), my_button2.grid_remove(), my_label.grid_remove(), my_button3.grid_remove(), cal.grid_remove(),lbl1.grid_remove(),lbl4.grid_remove(),lbl2.grid_remove(), lbl3.grid_remove(),lblT.grid_remove()]) my_button2= Button(root, text="назад",command=lambda: [step_2(), my_button2.grid_remove(), my_button.grid_remove(), my_button3.grid_remove(), my_label.grid_remove(), cal.grid_remove(), lbl1.grid_remove(),lbl4.grid_remove(),lbl2.grid_remove(), lbl3.grid_remove(),lblT.grid_remove()]) my_button3= Button(root, text="Вход в систему",command=lambda: [step_log(), my_button2.grid_remove(), my_button.grid_remove(), my_button3.grid_remove(), my_label.grid_remove(), cal.grid_remove(), lbl1.grid_remove(),lbl4.grid_remove(),lbl2.grid_remove(), lbl3.grid_remove(),lblT.grid_remove()]) my_label = Label(root, text='') my_button.grid(column=4, row=5, sticky="W") my_label.grid(column=5, row=5, sticky="W") my_button2.grid(column=1, row=5, sticky="W") my_button3.grid(column=0, row=0, sticky="N", pady=0,padx=0) lbl1 = tk.Label(root, text = '') lbl2 = tk.Label(root, text = 'ТЕСТ', font=("Arial Bold", 15)) lbl3 = tk.Label(root, text = '') lbl4 = tk.Label(root, text = '') lblT = tk.Label(root, text = 'Выберите дату ', font=("Arial Bold", 14)) #lbl1.grid(column=0, row=0, pady=0,padx=50) lbl2.grid(column=2, row=0, pady=5,padx=0) lbl3.grid(column=2, row=4, pady=0,padx=0) lbl4.grid(column=2, row=5, pady=0,padx=70) lblT.grid(column=2, row=1, pady=5,padx=0,columnspan=5, sticky="N") root.update()
def date_to_formatted(self, d): usage = getattr(aq_base(self.context), 'label_default', 'locale') locname = 'en_US' # default locale r_locale = get_locale(self.request) if r_locale and r_locale.id.territory: locname = '_'.join((r_locale.id.language, r_locale.id.territory)) cal1 = calendar.LocaleTextCalendar(locale=(locname, 'UTF-8')) name = cal1.formatmonthname(*d.timetuple()[:2], width=0) # month name if usage == 'abbr': return calendar.month_abbr[d.month] if usage == 'abbr+year': return '%s %s' % (calendar.month_abbr[d.month], d.year) if usage == 'name+year': return name if usage == 'name': return name.split(' ')[0] # name, no year return d.strftime('%m/%d/%Y')
def test_locale_calendars(self): old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) try: cal = calendar.LocaleTextCalendar(locale='') local_weekday = cal.formatweekday(1, 10) local_month = cal.formatmonthname(2010, 10, 10) except locale.Error: raise unittest.SkipTest('cannot set the system default locale') self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) self.assertEqual(len(local_weekday), 10) self.assertGreaterEqual(len(local_month), 10) cal = calendar.LocaleHTMLCalendar(locale='') local_weekday = cal.formatweekday(1) local_month = cal.formatmonthname(2010, 10) self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october)
def date(self, year, month, url): result = [] today = date.today() prev_month = month > 1 and month - 1 or 12 prev_year = prev_month == 12 and year - 1 or year item = self.dir_item() item['type'] = 'prev' item['url'] = "#date#%d#%d#%s" % (prev_year, prev_month, url) result.append(item) for d in calendar.LocaleTextCalendar().itermonthdates(year, month): if d.month != month: continue if d > today: break item = self.dir_item() item['title'] = "%d.%d %d" % (d.day, d.month, d.year) item['url'] = self._build_url(url, date=(d.day, d.month, d.year)) self._filter(result, item) result.reverse() return result
def __init__(self, master=None, **kw): """ WIDGET-SPECIFIC OPTIONS locale, firstweekday, year, month, selectbackground, selectforeground """ # remove custom options from kw before initializating ttk.Frame fwday = kw.pop('firstweekday', calendar.MONDAY) year = kw.pop('year', self.datetime.now().year) month = kw.pop('month', self.datetime.now().month) locale = kw.pop('locale', None) sel_bg = kw.pop('selectbackground', '#ecffc4') sel_fg = kw.pop('selectforeground', '#05640e') self._date = self.datetime(year, month, 1) self._selection = None # no date selected ttk.Frame.__init__(self, master, **kw) # instantiate proper calendar class if locale is None: self._cal = calendar.TextCalendar(fwday) else: self._cal = calendar.LocaleTextCalendar(fwday, locale) self.__setup_styles() # creates custom styles self.__place_widgets() # pack/grid used widgets self.__config_calendar() # adjust calendar columns and setup tags # configure a canvas, and proper bindings, for selecting dates self.__setup_selection(sel_bg, sel_fg) # store items ids, used for insertion later self._items = [ self._calendar.insert('', 'end', values='') for _ in range(6) ] # insert dates in the currently empty calendar self._build_calendar() # set the minimal size for the widget self._calendar.bind('<Map>', self.__minsize)
def spliceyear(vecka): # Chunk up the year c = calendar.LocaleTextCalendar(locale='sv_SE') for wholeyear in c.yeardatescalendar(year, 1): for months in wholeyear: for weeks in months: dennavecka = [] # Här kommer en vecka i taget # for days in weeks: d = datetime.date dt = d.timetuple(days) weeknumber = d.isocalendar(days) curryear = dt[0] month = monthname[dt[1]-1] datum = dt[2] weekday = dayname[dt[6]] veckonummer = weeknumber[1] dennavecka.append([month, veckonummer, datum, weekday, curryear]) vecka.append(dennavecka) return vecka
def test_locale_calendars(self): # ensure that Locale{Text,HTML}Calendar resets the locale properly # (it is still not thread-safe though) old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) try: cal = calendar.LocaleTextCalendar(locale='') local_weekday = cal.formatweekday(1, 10) local_month = cal.formatmonthname(2010, 10, 10) except locale.Error: # cannot set the system default locale -- skip rest of test raise unittest.SkipTest('cannot set the system default locale') self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) self.assertEqual(len(local_weekday), 10) self.assertGreaterEqual(len(local_month), 10) cal = calendar.LocaleHTMLCalendar(locale='') local_weekday = cal.formatweekday(1) local_month = cal.formatmonthname(2010, 10) self.assertIsInstance(local_weekday, str) self.assertIsInstance(local_month, str) new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10) self.assertEqual(old_october, new_october)
def get_calendar(locale, fwday): # instantiate proper calendar class if locale is None: return calendar.TextCalendar(fwday) else: return calendar.LocaleTextCalendar(fwday, locale)
def __get_calendar(s, locale, fwday): # 实例化适当的日历类 if locale is None: return calendar.TextCalendar(fwday) else: return calendar.LocaleTextCalendar(fwday, locale)
import json import time import calendar q = calendar.month(2018, 3) # w = calendar.mdays(0) t = calendar.LocaleTextCalendar() # print(q) print(t) a = time.time() b = time.localtime() c = time.asctime(b) d = time.clock() e = time.gmtime() print(a) print(b) print(c) print(d) print(e) string1 = ('worry', 'hello', 'njdnj') tuple1 = ('qwsw', 'deewded', 'dewdw', 231) list1 = ['dedw', '2333+23e', 'wedw', 'dewdwqdwede'] dict1 = {'A': 'a', 'B': 'b', 'C': 'c'} str2 = json.dumps(string1) print(str2) print(type(str2)) str3 = json.loads(str2) print(str3)
import calendar d = calendar.LocaleTextCalendar(6, "YdBA") d.pryear(2012)
import sys assert len(sys.argv) == 2, "need start year as the one and only parameter" startyear = sys.argv[1] assert startyear.isdigit(), "year must be positive numeric" startyear = int(startyear) assert startyear > 0, "year must be positive numeric" # We use a nicer mono-spaced font than the PDF builtin 'Courier'. # If you do not know one, set ffile to None and fname to 'Courier' ffile = "c:/windows/fonts/dejavusansmono.ttf" fname = "F0" doc = fitz.open() cal = calendar.LocaleTextCalendar(locale="es") # use your locale #cal = calendar.TextCalendar() # or stick with English w, h = fitz.PaperSize("a4-l") # get sizes for A4 landscape paper txt = cal.formatyear(startyear, m=4) doc.insertPage(-1, txt, fontsize=12, fontname=fname, fontfile=ffile, width=w, height=h) txt = cal.formatyear(startyear + 1, m=4) doc.insertPage(-1,
import calendar año = eval(input("Escribe un año: ")) mes = eval(input("Escribe un mes: ")) calendario = calendar.LocaleTextCalendar(locale='') print("El calendario del mes:\n", calendario.formatmonth(año, mes, 5, 3)) print("El calendario anual, en 2 filas:") calendario.pryear(año, m=6)
def get_calendar(locale, fwday): if locale is None: return calendar.TextCalendar(fwday) else: return calendar.LocaleTextCalendar(fwday, locale)
def __init__(self, master=None, **kw): """ Construct a Calendar with parent master. STANDARD OPTIONS cursor, font, borderwidth WIDGET-SPECIFIC OPTIONS year, month: initially displayed month, default is current month day: initially selected day, if month or year is given but not day, no initial selection, otherwise, default is today locale: locale to use, e.g. 'fr_FR.utf-8' (the locale need to be installed, otherwise it will raise 'locale.Error: unsupported locale setting') selectmode: "none" or "day" (default) define whether the user can change the selected day with a mouse click background: calendar border and month/year name background color foreground: month/year name foreground color bordercolor: day border color selectbackground: selected day background color selectforeground: selected day foreground color normalbackground: normal week days background color normalforeground: normal week days foreground color othermonthforeground: foreground color for normal week days belonging to the previous/next month othermonthbackground: background color for normal week days belonging to the previous/next month othermonthweforeground: foreground color for week-end days belonging to the previous/next month othermonthwebackground: background color for week-end days belonging to the previous/next month weekendbackground: week-end days background color weekendforeground: week-end days foreground color headersbackground: day names and week numbers background color headersforeground: day names and week numbers foreground color VIRTUAL EVENTS A <<CalendarSelected>> event is generated each time the user selects a day with the mouse. """ curs = kw.pop("cursor", "") font = kw.pop("font", "Liberation\ Sans 9") classname = kw.pop('class_', "Calendar") name = kw.pop('name', None) ttk.Frame.__init__(self, master, class_=classname, cursor=curs, name=name) self._style_prefixe = str(self) ttk.Frame.configure(self, style=self._style_prefixe + '.main.TFrame') self._font = Font(self, font) prop = self._font.actual() prop["size"] += 1 self._header_font = Font(self, **prop) try: bd = int(kw.pop('borderwidth', 2)) except ValueError: raise ValueError('expected integer for the borderwidth option.') # --- date today = self.date.today() if (("month" in kw) or ("year" in kw)) and ("day" not in kw): month = kw.pop("month", today.month) year = kw.pop('year', today.year) self._sel_date = None # selected day else: day = kw.pop('day', today.day) month = kw.pop("month", today.month) year = kw.pop('year', today.year) try: self._sel_date = self.date(year, month, day) # selected day except ValueError: self._sel_date = None self._date = self.date(year, month, 1) # (year, month) displayed by the calendar # --- selectmode selectmode = kw.pop("selectmode", "day") if selectmode not in ("none", "day"): raise ValueError("'selectmode' option should be 'none' or 'day'.") # --- locale locale = kw.pop("locale", None) if locale is None: self._cal = calendar.TextCalendar(calendar.MONDAY) else: self._cal = calendar.LocaleTextCalendar(calendar.MONDAY, locale) # --- style self.style = ttk.Style(self) active_bg = self.style.lookup('TEntry', 'selectbackground', ('focus', )) # --- properties options = [ 'cursor', 'font', 'borderwidth', 'selectmode', 'locale', 'selectbackground', 'selectforeground', 'normalbackground', 'normalforeground', 'background', 'foreground', 'bordercolor', 'othermonthforeground', 'othermonthbackground', 'othermonthweforeground', 'othermonthwebackground', 'weekendbackground', 'weekendforeground', 'headersbackground', 'headersforeground' ] keys = list(kw.keys()) for option in keys: if option not in options: del (kw[option]) self._properties = { "cursor": curs, "font": font, "borderwidth": bd, "locale": locale, "selectmode": selectmode, 'selectbackground': active_bg, 'selectforeground': 'white', 'normalbackground': 'white', 'normalforeground': 'black', 'background': 'gray30', 'foreground': 'white', 'bordercolor': 'gray70', 'othermonthforeground': 'gray45', 'othermonthbackground': 'gray93', 'othermonthweforeground': 'gray45', 'othermonthwebackground': 'gray75', 'weekendbackground': 'gray80', 'weekendforeground': 'gray30', 'headersbackground': 'gray70', 'headersforeground': 'black' } self._properties.update(kw) # --- init calendar # --- *-- header: month - year header = ttk.Frame(self, style=self._style_prefixe + '.main.TFrame') f_month = ttk.Frame(header, style=self._style_prefixe + '.main.TFrame') l_month = ttk.Button(f_month, style=self._style_prefixe + '.L.TButton', command=self._prev_month) self._header_month = ttk.Label(f_month, width=10, anchor='center', style=self._style_prefixe + '.main.TLabel', font=self._header_font) r_month = ttk.Button(f_month, style=self._style_prefixe + '.R.TButton', command=self._next_month) l_month.pack(side='left', fill="y") self._header_month.pack(side='left', padx=4) r_month.pack(side='left', fill="y") f_year = ttk.Frame(header, style=self._style_prefixe + '.main.TFrame') l_year = ttk.Button(f_year, style=self._style_prefixe + '.L.TButton', command=self._prev_year) self._header_year = ttk.Label(f_year, width=4, anchor='center', style=self._style_prefixe + '.main.TLabel', font=self._header_font) r_year = ttk.Button(f_year, style=self._style_prefixe + '.R.TButton', command=self._next_year) l_year.pack(side='left', fill="y") self._header_year.pack(side='left', padx=4) r_year.pack(side='left', fill="y") f_month.pack(side='left', fill='x') f_year.pack(side='right') # --- *-- calendar self._cal_frame = ttk.Frame(self, style=self._style_prefixe + '.cal.TFrame') ttk.Label(self._cal_frame, style=self._style_prefixe + '.headers.TLabel').grid( row=0, column=0, sticky="eswn") for i, d in enumerate(self._cal.formatweekheader(3).split()): self._cal_frame.columnconfigure(i + 1, weight=1) ttk.Label(self._cal_frame, font=self._font, style=self._style_prefixe + '.headers.TLabel', anchor="center", text=d, width=4).grid(row=0, column=i + 1, sticky="ew", pady=(0, 1)) self._week_nbs = [] self._calendar = [] for i in range(1, 7): self._cal_frame.rowconfigure(i, weight=1) wlabel = ttk.Label(self._cal_frame, style=self._style_prefixe + '.headers.TLabel', font=self._font, padding=2, anchor="e", width=2) self._week_nbs.append(wlabel) wlabel.grid(row=i, column=0, sticky="esnw", padx=(0, 1)) self._calendar.append([]) for j in range(1, 8): label = ttk.Label(self._cal_frame, style=self._style_prefixe + '.normal.TLabel', font=self._font, anchor="center") self._calendar[-1].append(label) label.grid(row=i, column=j, padx=(0, 1), pady=(0, 1), sticky="nsew") if selectmode is "day": label.bind("<1>", self._on_click) # --- *-- pack main elements header.pack(fill="x", padx=2, pady=2) self._cal_frame.pack(fill="both", expand=True, padx=bd, pady=bd) # --- bindings self.bind('<<ThemeChanged>>', self._setup_style) self._setup_style() self._display_calendar()
def __get_calendar(s, locale, fwday): # ʵ�����ʵ��������� if locale is None: return calendar.TextCalendar(fwday) else: return calendar.LocaleTextCalendar(fwday, locale)
import calendar cal = calendar.TextCalendar(firstweekday=3) # part b cal.pryear(2012) cal.prmonth(1999, 12, w=0, l=0) #part c d = calendar.LocaleTextCalendar(6, "CHINESE") #part d d.pryear(2012) print( calendar.isleap(2012) ) #part d Returns True if year is a leap year, otherwise False. It's called conditional function print(type(calendar.isleap))
''' Örnek 17.7. Takvim Uygulaması: Girilen bir yıla ait takvimi Türkçe olarak listeleyen programı yazınız. @author:Bülent Çobanoğlu ''' import calendar yil = int(input("Takvim yılını giriniz:")) cal = calendar.LocaleTextCalendar(0, "TURKISH") # Bir takvim nesnesi oluştur cal.pryear(yil) #alternatifi: print(calendar.prcal(yil))