Python calendar 模块,SUNDAY 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用calendar.SUNDAY

项目:slaveo    作者:lamter    | 项目源码 | 文件源码
def _weekend_trade_day_type(self, dates):
        types = []
        weekdays = []
        for dt in dates:
            weekday = dt.date().weekday()
            # ????????
            if weekday == calendar.MONDAY:
                # ?????????
                _types = TRADE_DAY_TYPE_FIRST
            elif weekday == calendar.FRIDAY:
                # ????
                _types = TRADE_DAY_TYPE_FRI
            elif weekday == calendar.SATURDAY:
                # ????
                _types = TRADE_DAY_TYPE_SAT
            elif weekday == calendar.SUNDAY:
                # ??
                _types = TRADE_DAY_TYPE_HOLIDAY
            else:
                # ?????
                _types = TRADE_DAY_TYPE_NORMAL

            types.append(_types)
            weekdays.append(weekday)
        return types, weekdays
项目:chains    作者:hc-12    | 项目源码 | 文件源码
def get_weekday_format(year, month, day, include_weekend=True):
    """return numeric day in string if weekday else day with WEEKEND_SYMBOL"""
    weekend = [calendar.SATURDAY, calendar.SUNDAY]
    d = calendar.weekday(year, month, day)
    # highlight_wkend = False
    # global WEEKEND_SYMBOL

    # WEEKEND_SYMBOL = ' '
    if d in weekend:
        if include_weekend:
            return "{ws}{day}  ".format(ws=WEEKEND_SYMBOL, day=day)
        else:
            return ""

    return " {day}  ".format(day=day)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)
项目:tk_tools    作者:slightlynybbled    | 项目源码 | 文件源码
def __init__(self, master=None, callback=None, **kw):
        """
        WIDGET-SPECIFIC OPTIONS

            locale, firstweekday, year, month, selectbackground,
            selectforeground
        """
        # remove custom options from kw before initializing ttk.Frame
        fwday = calendar.SUNDAY
        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
        self.callback = callback

        super().__init__(master, **kw)

        self._cal = _get_calendar(locale, fwday)

        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()
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test():
    import sys
    root = Tkinter.Tk()
    root.title('Ttk Calendar')
    ttkcal = Calendar(firstweekday=calendar.SUNDAY)
    ttkcal.pack(expand=1, fill='both')

    if 'win' not in sys.platform:
        style = ttk.Style()
        style.theme_use('clam')

    root.mainloop()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)
项目:pyconjpbot    作者:pyconjp    | 项目源码 | 文件源码
def cal_command(message, month=None, year=None):
    """
    ????????????
    """
    today = date.today()
    month = int(month) if month else today.month
    year = int(year) if year else today.year

    cal = calendar.TextCalendar(firstweekday=calendar.SUNDAY)
    try:
        botsend(message, '```{}```'.format(cal.formatmonth(year, month)))
    except IndexError:
        # ??????????????
        pass
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)
项目:ksupcapp    作者:SkydiveK-State    | 项目源码 | 文件源码
def tandem_choose_date(request, year=datetime.now().year, month=datetime.now().month, template_name='signup/tandem_choose_date.html'):

    month, year = int(month), int(year)
    c = calendar.Calendar()
    c.setfirstweekday(calendar.SUNDAY)
    cal = c.monthdatescalendar(year, month)

    _events = TandemDay.objects.filter(date__range=(cal[0][0], cal[len(cal) - 1][6]))
    events = {}
    for e in _events:
        if e.date.month not in events:
            events[e.date.month] = {}
        if e.date.day not in events[e.date.month]:
            events[e.date.month][e.date.day] = []
        events[e.date.month][e.date.day].append(e)

    print(events)

    data = {}
    data['title'] = "Tandem Sign Up"
    data['month_name'] = calendar.month_name[month]
    data['year'] = year
    data['month'] = month
    data['previous'] = {'month': (month - 1 + 11) % 12 + 1, 'year': year - (1 if month == 1 else 0)}
    data['next'] = {'month': (month - 1 + 1) % 12 + 1, 'year': year + (1 if month == 12 else 0)}
    data['calendar'] = cal
    data['events'] = events
    data['nofollow'] = (True if year < 2017 or year > datetime.now().year + 2 else False)
    return render(request, template_name, data)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_setfirstweekday(self):
        self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig)