MCPcopy Create free account
hub / github.com/ActiveState/code / LocaleTime

Class LocaleTime

recipes/Python/56036_Pure_Python_strptime/recipe-56036.py:77–217  ·  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

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

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected