MCPcopy Index your code
hub / github.com/python/cpython / LocaleTime

Class LocaleTime

Lib/_strptime.py:68–337  ·  view source on GitHub ↗

Stores and handles locale-specific information related to time. ATTRIBUTES: f_weekday -- full weekday names (7-item list) a_weekday -- abbreviated weekday names (7-item list) f_month -- full month names (13-item list; dummy value in [0], which is adde

Source from the content-addressed store, hash-verified

66
67
68class LocaleTime(object):
69 """Stores and handles locale-specific information related to time.
70
71 ATTRIBUTES:
72 f_weekday -- full weekday names (7-item list)
73 a_weekday -- abbreviated weekday names (7-item list)
74 f_month -- full month names (13-item list; dummy value in [0], which
75 is added by code)
76 a_month -- abbreviated month names (13-item list, dummy value in
77 [0], which is added by code)
78 am_pm -- AM/PM representation (2-item list)
79 LC_date_time -- format string for date/time representation (string)
80 LC_date -- format string for date representation (string)
81 LC_time -- format string for time representation (string)
82 timezone -- daylight- and non-daylight-savings timezone representation
83 (2-item list of sets)
84 lang -- Language used by instance (2-item tuple)
85 """
86
87 def __init__(self):
88 """Set all attributes.
89
90 Order of methods called matters for dependency reasons.
91
92 The locale language is set at the offset and then checked again before
93 exiting. This is to make sure that the attributes were not set with a
94 mix of information from more than one locale. This would most likely
95 happen when using threads where one thread calls a locale-dependent
96 function while another thread changes the locale while the function in
97 the other thread is still running. Proper coding would call for
98 locks to prevent changing the locale while locale-dependent code is
99 running. The check here is done in case someone does not think about
100 doing this.
101
102 Only other possible issue is if someone changed the timezone and did
103 not call tz.tzset . That is an issue for the programmer, though,
104 since changing the timezone is worthless without that call.
105
106 """
107 self.lang = _getlang()
108 self.__calc_weekday()
109 self.__calc_month()
110 self.__calc_am_pm()
111 self.__calc_alt_digits()
112 self.__calc_timezone()
113 self.__calc_date_time()
114 if _getlang() != self.lang:
115 raise ValueError("locale changed during initialization")
116 if time.tzname != self.tzname or time.daylight != self.daylight:
117 raise ValueError("timezone changed during initialization")
118
119 def __calc_weekday(self):
120 # Set self.a_weekday and self.f_weekday using the calendar
121 # module.
122 a_weekday = [calendar.day_abbr[i].lower() for i in range(7)]
123 f_weekday = [calendar.day_name[i].lower() for i in range(7)]
124 self.a_weekday = a_weekday
125 self.f_weekday = f_weekday

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…