Python calendar.day_name() Examples
The following are 30
code examples of calendar.day_name().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
calendar
, or try the search function
.
Example #1
Source File: __init__.py From pyirobot with MIT License | 7 votes |
def GetSchedule(self): """ Get the cleaning schedule for this robot Returns: A dictionary representing the schedule per day (dict) """ res = self._PostToRobot("get", "week") schedule = {} for idx in range(7): cal_day_idx = idx - 1 if cal_day_idx < 0: cal_day_idx = 6 schedule[calendar.day_name[cal_day_idx]] = { "clean" : True if res["cycle"][idx] == "start" else False, "startTime" : datetime.time(res["h"][idx], res["m"][idx]) } return schedule
Example #2
Source File: test_timestamp.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_names(self, data, time_locale): # GH 17354 # Test .weekday_name, .day_name(), .month_name with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert data.weekday_name == 'Monday' if time_locale is None: expected_day = 'Monday' expected_month = 'August' else: with tm.set_locale(time_locale, locale.LC_TIME): expected_day = calendar.day_name[0].capitalize() expected_month = calendar.month_name[8].capitalize() assert data.day_name(time_locale) == expected_day assert data.month_name(time_locale) == expected_month # Test NaT nan_ts = Timestamp(NaT) assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale))
Example #3
Source File: htmlreportcreator.py From repostat with GNU General Public License v3.0 | 6 votes |
def __init__(self, config: Configuration, repository: GitRepository): self.path = None self.configuration = config self.assets_path = os.path.join(HERE, self.assets_subdir) self.git_repository_statistics = repository self.has_tags_page = config.do_process_tags() self._time_sampling_interval = "W" self._do_generate_index_page = False self._is_blame_data_allowed = False self._max_orphaned_extensions_count = 0 templates_dir = os.path.join(HERE, self.templates_subdir) self.j2_env = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True) self.j2_env.filters['to_month_name_abr'] = lambda im: calendar.month_abbr[im] self.j2_env.filters['to_weekday_name'] = lambda i: calendar.day_name[i] self.j2_env.filters['to_ratio'] = lambda val, max_val: (float(val) / max_val) if max_val != 0 else 0 self.j2_env.filters['to_percentage'] = lambda val, max_val: (100 * float(val) / max_val) if max_val != 0 else 0 colors = colormaps.colormaps[self.configuration['colormap']] self.j2_env.filters['to_heatmap'] = lambda val, max_val: "%d, %d, %d" % colors[int(float(val) / max_val * (len(colors) - 1))]
Example #4
Source File: ExpressionDescriptor.py From cron-descriptor with MIT License | 6 votes |
def number_to_day(self, day_number): """Returns localized day name by its CRON number Args: day_number: Number of a day Returns: Day corresponding to day_number Raises: IndexError: When day_number is not found """ return [ calendar.day_name[6], calendar.day_name[0], calendar.day_name[1], calendar.day_name[2], calendar.day_name[3], calendar.day_name[4], calendar.day_name[5] ][day_number]
Example #5
Source File: delta_time.py From pyparsing with MIT License | 6 votes |
def convert_abs_day_reference_to_date(t): now = datetime.now().replace(microsecond=0) # handle day reference by weekday name if "day_name" in t: todaynum = now.weekday() daynames = [n.lower() for n in weekday_name_list] nameddaynum = daynames.index(t.day_name.lower()) # compute difference in days - if current weekday name is referenced, then # computed 0 offset is changed to 7 if t.dir > 0: daydiff = (nameddaynum + 7 - todaynum) % 7 or 7 else: daydiff = -((todaynum + 7 - nameddaynum) % 7 or 7) t["abs_date"] = datetime(now.year, now.month, now.day) + timedelta(daydiff) else: name = t[0] t["abs_date"] = { "now": now, "today": datetime(now.year, now.month, now.day), "yesterday": datetime(now.year, now.month, now.day) + timedelta(days=-1), "tomorrow": datetime(now.year, now.month, now.day) + timedelta(days=+1), }[name]
Example #6
Source File: test_timestamp.py From vnpy_crypto with MIT License | 6 votes |
def test_names(self, data, time_locale): # GH 17354 # Test .weekday_name, .day_name(), .month_name with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): assert data.weekday_name == 'Monday' if time_locale is None: expected_day = 'Monday' expected_month = 'August' else: with tm.set_locale(time_locale, locale.LC_TIME): expected_day = calendar.day_name[0].capitalize() expected_month = calendar.month_name[8].capitalize() assert data.day_name(time_locale) == expected_day assert data.month_name(time_locale) == expected_month # Test NaT nan_ts = Timestamp(NaT) assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale))
Example #7
Source File: deltaTime.py From phpsploit with GNU General Public License v3.0 | 6 votes |
def convertToDay(toks): now = datetime.now() if "wkdayRef" in toks: todaynum = now.weekday() daynames = [n.lower() for n in calendar.day_name] nameddaynum = daynames.index(toks.wkdayRef.day.lower()) if toks.wkdayRef.dir > 0: daydiff = (nameddaynum + 7 - todaynum) % 7 else: daydiff = -((todaynum + 7 - nameddaynum) % 7) toks["absTime"] = datetime(now.year, now.month, now.day)+timedelta(daydiff) else: name = toks.name.lower() toks["absTime"] = { "now" : now, "today" : datetime(now.year, now.month, now.day), "yesterday" : datetime(now.year, now.month, now.day)+timedelta(-1), "tomorrow" : datetime(now.year, now.month, now.day)+timedelta(+1), }[name]
Example #8
Source File: stormtypes.py From synapse with Apache License 2.0 | 5 votes |
def _parseWeekday(self, val): ''' Try to match a day-of-week abbreviation, then try a day-of-week full name ''' val = val.title() try: return list(calendar.day_abbr).index(val) except ValueError: try: return list(calendar.day_name).index(val) except ValueError: return None
Example #9
Source File: _strptime.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #10
Source File: cron.py From synapse with Apache License 2.0 | 5 votes |
def _parse_weekday(val): ''' Try to match a day-of-week abbreviation, then try a day-of-week full name ''' val = val.title() try: return list(calendar.day_abbr).index(val) except ValueError: try: return list(calendar.day_name).index(val) except ValueError: return None
Example #11
Source File: __init__.py From pyirobot with MIT License | 5 votes |
def SetSchedule(self, newSchedule): """ Set the cleaning schedule for this robot. The easiest way to use this function is to call GetSchedule, modify the result, and use that as the input to this function Args: schedule: the schedule to set (dict) """ # Sort calendar day names into the order the robot expects days = {} for cal_idx, dayname in enumerate(calendar.day_name): idx = cal_idx + 1 if cal_idx < 6 else 0 days[idx] = dayname sched = collections.OrderedDict([ ("cycle", []), ("h", []), ("m", []) ]) for idx in sorted(days): dayname = days[idx] if newSchedule[dayname]["clean"]: sched["cycle"].append("start") else: sched["cycle"].append("none") sched["h"].append(newSchedule[dayname]["startTime"].hour) sched["m"].append(newSchedule[dayname]["startTime"].minute) self._PostToRobot("set", ["week", sched])
Example #12
Source File: strategy.py From trading-server with GNU General Public License v3.0 | 5 votes |
def get_relevant_timeframes(self, time): """ Return a list of timeframes relevant to the just-elapsed period. E.g if time has just struck UTC 10:30am the list will contain "1min", "3Min", "5Min", "15Min" and "30Min" strings. The first minute of a new day or week will add daily/weekly/monthly timeframe strings. Args: time: datetime object Returns: timeframes: list containing relevant timeframe string codes. Raises: None. """ # Check against the previous minute - the just-elapsed period. if type(time) is not datetime: time = datetime.utcfromtimestamp(time) timestamp = time - timedelta(hours=0, minutes=1) timeframes = [] self.logger.debug("Timestamp just elapsed: " + str(timestamp)) for i in self.MINUTE_TIMEFRAMES: self.minute_timeframe(i, timestamp, timeframes) for i in self.HOUR_TIMEFRAMES: self.hour_timeframe(i, timestamp, timeframes) for i in self.DAY_TIMEFRAMES: self.day_timeframe(i, timestamp, timeframes) # if (timestamp.minute == 0 and timestamp.hour == 0 and # calendar.day_name[date.today().weekday()] == "Monday"): # timeframes.append("7D") return timeframes
Example #13
Source File: test_datetime_values.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_dt_accessor_datetime_name_accessors(self, time_locale): # Test Monday -> Sunday and January -> December, in that sequence if time_locale is None: # If the time_locale is None, day-name and month_name should # return the english attributes expected_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] expected_months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] else: with tm.set_locale(time_locale, locale.LC_TIME): expected_days = calendar.day_name[:] expected_months = calendar.month_name[1:] s = Series(DatetimeIndex(freq='D', start=datetime(1998, 1, 1), periods=365)) english_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] for day, name, eng_name in zip(range(4, 11), expected_days, english_days): name = name.capitalize() assert s.dt.weekday_name[day] == eng_name assert s.dt.day_name(locale=time_locale)[day] == name s = s.append(Series([pd.NaT])) assert np.isnan(s.dt.day_name(locale=time_locale).iloc[-1]) s = Series(DatetimeIndex(freq='M', start='2012', end='2013')) result = s.dt.month_name(locale=time_locale) expected = Series([month.capitalize() for month in expected_months]) tm.assert_series_equal(result, expected) for s_date, expected in zip(s, expected_months): result = s_date.month_name(locale=time_locale) assert result == expected.capitalize() s = s.append(Series([pd.NaT])) assert np.isnan(s.dt.month_name(locale=time_locale).iloc[-1])
Example #14
Source File: _strptime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #15
Source File: _strptime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #16
Source File: group.py From homematicip-rest-api with GNU General Public License v3.0 | 5 votes |
def update_profile(self): days = {} for i in xrange(0, 7): periods = [] day = self.profileDays[i] for p in day.periods: periods.append( { "endtime": p.endtime, "starttime": p.starttime, "value": p.value, "endtimeAsMinutesOfDay": self._time_to_totalminutes(p.endtime), "starttimeAsMinutesOfDay": self._time_to_totalminutes( p.starttime ), } ) dayOfWeek = calendar.day_name[i].upper() days[dayOfWeek] = { "baseValue": day.baseValue, "dayOfWeek": dayOfWeek, "periods": periods, } data = { "groupId": self.groupId, "profile": { "groupId": self.groupId, "homeId": self.homeId, "id": self.id, "index": self.index, "name": self.name, "profileDays": days, "type": self.type, }, "profileIndex": self.index, } return self._restCall("group/heating/updateProfile", body=json.dumps(data))
Example #17
Source File: group.py From homematicip-rest-api with GNU General Public License v3.0 | 5 votes |
def get_details(self): data = { "groupId": self.groupId, "profileIndex": self.index, "profileName": self.name, } js = self._restCall("group/heating/getProfile", body=json.dumps(data)) self.homeId = js["homeId"] self.type = js["type"] self.profileDays = {} for i in range(0, 7): day = HeatingCoolingProfileDay(self._connection) day.from_json(js["profileDays"][calendar.day_name[i].upper()]) self.profileDays[i] = day
Example #18
Source File: _strptime.py From canape with GNU General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #19
Source File: test_maya.py From maya with MIT License | 5 votes |
def test_when_future_day_name(): two_days_away = maya.now().add(days=2) future_date = maya.when( calendar.day_name[two_days_away.weekday], prefer_dates_from="future" ) assert future_date > maya.now()
Example #20
Source File: _strptime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #21
Source File: _strptime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #22
Source File: _strptime.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #23
Source File: date.py From anki-search-inside-add-card with GNU Affero General Public License v3.0 | 5 votes |
def weekday_name_from_dt(dt: datetime) -> str: # return calendar.day_name[dt.weekday()] locale.setlocale(locale.LC_TIME, 'en_US.UTF-8') return dt.strftime("%A")
Example #24
Source File: date.py From anki-search-inside-add-card with GNU Affero General Public License v3.0 | 5 votes |
def weekday_name(wd: int) -> str: return list(calendar.day_name)[wd - 1]
Example #25
Source File: _strptime.py From medicare-demo with Apache License 2.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #26
Source File: _strptime.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday
Example #27
Source File: test_weekday_setbuilder.py From aws-ops-automator with Apache License 2.0 | 5 votes |
def test_name(self): for i, day_name in enumerate(calendar.day_abbr): self.assertEqual(WeekdaySetBuilder().build(day_name), {i}) for i, day_name in enumerate(calendar.day_name): self.assertEqual(WeekdaySetBuilder().build(day_name), {i})
Example #28
Source File: test_maya.py From maya with MIT License | 5 votes |
def test_when_past_day_name(): two_days_away = maya.now().add(days=2) past_date = maya.when( calendar.day_name[two_days_away.weekday], prefer_dates_from="past" ) assert past_date < maya.now()
Example #29
Source File: wizard.py From stdm with GNU General Public License v2.0 | 5 votes |
def get_time_stamp(self): """ Return a formatted day of week and date/time """ cdate = date.today() week_day = calendar.day_name[cdate.weekday()][:3] fmt_date = datetime.now().strftime('%d-%m-%Y %H:%M') time_stamp = week_day+' '+fmt_date return time_stamp
Example #30
Source File: _strptime.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def __calc_weekday(self): # Set self.a_weekday and self.f_weekday using the calendar # module. a_weekday = [calendar.day_abbr[i].lower() for i in range(7)] f_weekday = [calendar.day_name[i].lower() for i in range(7)] self.a_weekday = a_weekday self.f_weekday = f_weekday