annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/DateTime/interfaces.py @ 68:5028fdace37b

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