Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/DateTime/interfaces.py @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 ############################################################################## | |
2 # | |
3 # Copyright (c) 2005 Zope Foundation and Contributors. | |
4 # | |
5 # This software is subject to the provisions of the Zope Public License, | |
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | |
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | |
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | |
10 # FOR A PARTICULAR PURPOSE | |
11 # | |
12 ############################################################################## | |
13 from zope.interface import Interface | |
14 | |
15 | |
16 class DateTimeError(Exception): | |
17 pass | |
18 | |
19 | |
20 class SyntaxError(DateTimeError): | |
21 pass | |
22 | |
23 | |
24 class DateError(DateTimeError): | |
25 pass | |
26 | |
27 | |
28 class TimeError(DateTimeError): | |
29 pass | |
30 | |
31 | |
32 class IDateTime(Interface): | |
33 # Conversion and comparison methods | |
34 | |
35 def localZone(ltm=None): | |
36 """Returns the time zone on the given date. The time zone | |
37 can change according to daylight savings.""" | |
38 | |
39 def timeTime(): | |
40 """Return the date/time as a floating-point number in UTC, in | |
41 the format used by the Python time module. Note that it is | |
42 possible to create date/time values with DateTime that have no | |
43 meaningful value to the time module.""" | |
44 | |
45 def toZone(z): | |
46 """Return a DateTime with the value as the current object, | |
47 represented in the indicated timezone.""" | |
48 | |
49 def isFuture(): | |
50 """Return true if this object represents a date/time later | |
51 than the time of the call""" | |
52 | |
53 def isPast(): | |
54 """Return true if this object represents a date/time earlier | |
55 than the time of the call""" | |
56 | |
57 def isCurrentYear(): | |
58 """Return true if this object represents a date/time that | |
59 falls within the current year, in the context of this | |
60 object's timezone representation""" | |
61 | |
62 def isCurrentMonth(): | |
63 """Return true if this object represents a date/time that | |
64 falls within the current month, in the context of this | |
65 object's timezone representation""" | |
66 | |
67 def isCurrentDay(): | |
68 """Return true if this object represents a date/time that | |
69 falls within the current day, in the context of this object's | |
70 timezone representation""" | |
71 | |
72 def isCurrentHour(): | |
73 """Return true if this object represents a date/time that | |
74 falls within the current hour, in the context of this object's | |
75 timezone representation""" | |
76 | |
77 def isCurrentMinute(): | |
78 """Return true if this object represents a date/time that | |
79 falls within the current minute, in the context of this | |
80 object's timezone representation""" | |
81 | |
82 def isLeapYear(): | |
83 """Return true if the current year (in the context of the | |
84 object's timezone) is a leap year""" | |
85 | |
86 def earliestTime(): | |
87 """Return a new DateTime object that represents the earliest | |
88 possible time (in whole seconds) that still falls within the | |
89 current object's day, in the object's timezone context""" | |
90 | |
91 def latestTime(): | |
92 """Return a new DateTime object that represents the latest | |
93 possible time (in whole seconds) that still falls within the | |
94 current object's day, in the object's timezone context""" | |
95 | |
96 def greaterThan(t): | |
97 """Compare this DateTime object to another DateTime object OR | |
98 a floating point number such as that which is returned by the | |
99 Python time module. Returns true if the object represents a | |
100 date/time greater than the specified DateTime or time module | |
101 style time. Revised to give more correct results through | |
102 comparison of long integer milliseconds.""" | |
103 | |
104 __gt__ = greaterThan | |
105 | |
106 def greaterThanEqualTo(t): | |
107 """Compare this DateTime object to another DateTime object OR | |
108 a floating point number such as that which is returned by the | |
109 Python time module. Returns true if the object represents a | |
110 date/time greater than or equal to the specified DateTime or | |
111 time module style time. Revised to give more correct results | |
112 through comparison of long integer milliseconds.""" | |
113 | |
114 __ge__ = greaterThanEqualTo | |
115 | |
116 def equalTo(t): | |
117 """Compare this DateTime object to another DateTime object OR | |
118 a floating point number such as that which is returned by the | |
119 Python time module. Returns true if the object represents a | |
120 date/time equal to the specified DateTime or time module style | |
121 time. Revised to give more correct results through comparison | |
122 of long integer milliseconds.""" | |
123 | |
124 __eq__ = equalTo | |
125 | |
126 def notEqualTo(t): | |
127 """Compare this DateTime object to another DateTime object OR | |
128 a floating point number such as that which is returned by the | |
129 Python time module. Returns true if the object represents a | |
130 date/time not equal to the specified DateTime or time module | |
131 style time. Revised to give more correct results through | |
132 comparison of long integer milliseconds.""" | |
133 | |
134 __ne__ = notEqualTo | |
135 | |
136 def lessThan(t): | |
137 """Compare this DateTime object to another DateTime object OR | |
138 a floating point number such as that which is returned by the | |
139 Python time module. Returns true if the object represents a | |
140 date/time less than the specified DateTime or time module | |
141 style time. Revised to give more correct results through | |
142 comparison of long integer milliseconds.""" | |
143 | |
144 __lt__ = lessThan | |
145 | |
146 def lessThanEqualTo(t): | |
147 """Compare this DateTime object to another DateTime object OR | |
148 a floating point number such as that which is returned by the | |
149 Python time module. Returns true if the object represents a | |
150 date/time less than or equal to the specified DateTime or time | |
151 module style time. Revised to give more correct results | |
152 through comparison of long integer milliseconds.""" | |
153 | |
154 __le__ = lessThanEqualTo | |
155 | |
156 # Component access | |
157 | |
158 def parts(): | |
159 """Return a tuple containing the calendar year, month, day, | |
160 hour, minute second and timezone of the object""" | |
161 | |
162 def timezone(): | |
163 """Return the timezone in which the object is represented.""" | |
164 | |
165 def tzoffset(): | |
166 """Return the timezone offset for the objects timezone.""" | |
167 | |
168 def year(): | |
169 """Return the calendar year of the object""" | |
170 | |
171 def month(): | |
172 """Return the month of the object as an integer""" | |
173 | |
174 def Month(): | |
175 """Return the full month name""" | |
176 | |
177 def aMonth(): | |
178 """Return the abbreviated month name.""" | |
179 | |
180 def Mon(): | |
181 """Compatibility: see aMonth""" | |
182 | |
183 def pMonth(): | |
184 """Return the abbreviated (with period) month name.""" | |
185 | |
186 def Mon_(): | |
187 """Compatibility: see pMonth""" | |
188 | |
189 def day(): | |
190 """Return the integer day""" | |
191 | |
192 def Day(): | |
193 """Return the full name of the day of the week""" | |
194 | |
195 def DayOfWeek(): | |
196 """Compatibility: see Day""" | |
197 | |
198 def dayOfYear(): | |
199 """Return the day of the year, in context of the timezone | |
200 representation of the object""" | |
201 | |
202 def aDay(): | |
203 """Return the abbreviated name of the day of the week""" | |
204 | |
205 def pDay(): | |
206 """Return the abbreviated (with period) name of the day of the | |
207 week""" | |
208 | |
209 def Day_(): | |
210 """Compatibility: see pDay""" | |
211 | |
212 def dow(): | |
213 """Return the integer day of the week, where sunday is 0""" | |
214 | |
215 def dow_1(): | |
216 """Return the integer day of the week, where sunday is 1""" | |
217 | |
218 def h_12(): | |
219 """Return the 12-hour clock representation of the hour""" | |
220 | |
221 def h_24(): | |
222 """Return the 24-hour clock representation of the hour""" | |
223 | |
224 def ampm(): | |
225 """Return the appropriate time modifier (am or pm)""" | |
226 | |
227 def hour(): | |
228 """Return the 24-hour clock representation of the hour""" | |
229 | |
230 def minute(): | |
231 """Return the minute""" | |
232 | |
233 def second(): | |
234 """Return the second""" | |
235 | |
236 def millis(): | |
237 """Return the millisecond since the epoch in GMT.""" | |
238 | |
239 def strftime(format): | |
240 """Format the date/time using the *current timezone representation*.""" | |
241 | |
242 # General formats from previous DateTime | |
243 | |
244 def Date(): | |
245 """Return the date string for the object.""" | |
246 | |
247 def Time(): | |
248 """Return the time string for an object to the nearest second.""" | |
249 | |
250 def TimeMinutes(): | |
251 """Return the time string for an object not showing seconds.""" | |
252 | |
253 def AMPM(): | |
254 """Return the time string for an object to the nearest second.""" | |
255 | |
256 def AMPMMinutes(): | |
257 """Return the time string for an object not showing seconds.""" | |
258 | |
259 def PreciseTime(): | |
260 """Return the time string for the object.""" | |
261 | |
262 def PreciseAMPM(): | |
263 """Return the time string for the object.""" | |
264 | |
265 def yy(): | |
266 """Return calendar year as a 2 digit string""" | |
267 | |
268 def mm(): | |
269 """Return month as a 2 digit string""" | |
270 | |
271 def dd(): | |
272 """Return day as a 2 digit string""" | |
273 | |
274 def rfc822(): | |
275 """Return the date in RFC 822 format""" | |
276 | |
277 # New formats | |
278 | |
279 def fCommon(): | |
280 """Return a string representing the object's value in the | |
281 format: March 1, 1997 1:45 pm""" | |
282 | |
283 def fCommonZ(): | |
284 """Return a string representing the object's value in the | |
285 format: March 1, 1997 1:45 pm US/Eastern""" | |
286 | |
287 def aCommon(): | |
288 """Return a string representing the object's value in the | |
289 format: Mar 1, 1997 1:45 pm""" | |
290 | |
291 def aCommonZ(): | |
292 """Return a string representing the object's value in the | |
293 format: Mar 1, 1997 1:45 pm US/Eastern""" | |
294 | |
295 def pCommon(): | |
296 """Return a string representing the object's value in the | |
297 format: Mar. 1, 1997 1:45 pm""" | |
298 | |
299 def pCommonZ(): | |
300 """Return a string representing the object's value | |
301 in the format: Mar. 1, 1997 1:45 pm US/Eastern""" | |
302 | |
303 def ISO(): | |
304 """Return the object in ISO standard format. Note: this is | |
305 *not* ISO 8601-format! See the ISO8601 and HTML4 methods below | |
306 for ISO 8601-compliant output | |
307 | |
308 Dates are output as: YYYY-MM-DD HH:MM:SS | |
309 """ | |
310 | |
311 def ISO8601(): | |
312 """Return the object in ISO 8601-compatible format containing | |
313 the date, time with seconds-precision and the time zone | |
314 identifier - see http://www.w3.org/TR/NOTE-datetime | |
315 | |
316 Dates are output as: YYYY-MM-DDTHH:MM:SSTZD | |
317 T is a literal character. | |
318 TZD is Time Zone Designator, format +HH:MM or -HH:MM | |
319 | |
320 The HTML4 method below offers the same formatting, but | |
321 converts to UTC before returning the value and sets the TZD"Z" | |
322 """ | |
323 | |
324 def HTML4(): | |
325 """Return the object in the format used in the HTML4.0 | |
326 specification, one of the standard forms in ISO8601. See | |
327 http://www.w3.org/TR/NOTE-datetime | |
328 | |
329 Dates are output as: YYYY-MM-DDTHH:MM:SSZ | |
330 T, Z are literal characters. | |
331 The time is in UTC. | |
332 """ | |
333 | |
334 def JulianDay(): | |
335 """Return the Julian day according to | |
336 https://www.tondering.dk/claus/cal/julperiod.php#formula | |
337 """ | |
338 | |
339 def week(): | |
340 """Return the week number according to ISO. | |
341 | |
342 See https://www.tondering.dk/claus/cal/week.php#weekno | |
343 """ | |
344 | |
345 # Python operator and conversion API | |
346 | |
347 def __add__(other): | |
348 """A DateTime may be added to a number and a number may be | |
349 added to a DateTime; two DateTimes cannot be added.""" | |
350 | |
351 __radd__ = __add__ | |
352 | |
353 def __sub__(other): | |
354 """Either a DateTime or a number may be subtracted from a | |
355 DateTime, however, a DateTime may not be subtracted from a | |
356 number.""" | |
357 | |
358 def __repr__(): | |
359 """Convert a DateTime to a string that looks like a Python | |
360 expression.""" | |
361 | |
362 def __str__(): | |
363 """Convert a DateTime to a string.""" | |
364 | |
365 def __hash__(): | |
366 """Compute a hash value for a DateTime""" | |
367 | |
368 def __int__(): | |
369 """Convert to an integer number of seconds since the epoch (gmt)""" | |
370 | |
371 def __long__(): | |
372 """Convert to a long-int number of seconds since the epoch (gmt)""" | |
373 | |
374 def __float__(): | |
375 """Convert to floating-point number of seconds since the epoch (gmt)""" |