METADATA 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. Metadata-Version: 2.0
  2. Name: DateTime
  3. Version: 4.3
  4. Summary: This package provides a DateTime data type, as known from Zope. Unless you need to communicate with Zope APIs, you're probably better off using Python's built-in datetime module.
  5. Home-page: https://github.com/zopefoundation/DateTime
  6. Author: Zope Foundation and Contributors
  7. Author-email: zope-dev@zope.org
  8. License: ZPL 2.1
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 6 - Mature
  11. Classifier: Environment :: Web Environment
  12. Classifier: Framework :: Zope :: 4
  13. Classifier: License :: OSI Approved :: Zope Public License
  14. Classifier: Operating System :: OS Independent
  15. Classifier: Programming Language :: Python
  16. Classifier: Programming Language :: Python :: 2
  17. Classifier: Programming Language :: Python :: 2.7
  18. Classifier: Programming Language :: Python :: 3
  19. Classifier: Programming Language :: Python :: 3.4
  20. Classifier: Programming Language :: Python :: 3.5
  21. Classifier: Programming Language :: Python :: 3.6
  22. Classifier: Programming Language :: Python :: 3.7
  23. Classifier: Programming Language :: Python :: Implementation :: CPython
  24. Classifier: Programming Language :: Python :: Implementation :: PyPy
  25. Requires-Dist: pytz
  26. Requires-Dist: zope.interface
  27. The DateTime package
  28. ====================
  29. Encapsulation of date/time values.
  30. Function Timezones()
  31. --------------------
  32. Returns the list of recognized timezone names:
  33. >>> from DateTime import Timezones
  34. >>> zones = set(Timezones())
  35. Almost all of the standard pytz timezones are included, with the exception
  36. of some commonly-used but ambiguous abbreviations, where historical Zope
  37. usage conflicts with the name used by pytz:
  38. >>> import pytz
  39. >>> [x for x in pytz.all_timezones if x not in zones]
  40. ['CET', 'EET', 'EST', 'MET', 'MST', 'WET']
  41. Class DateTime
  42. --------------
  43. DateTime objects represent instants in time and provide interfaces for
  44. controlling its representation without affecting the absolute value of
  45. the object.
  46. DateTime objects may be created from a wide variety of string or
  47. numeric data, or may be computed from other DateTime objects.
  48. DateTimes support the ability to convert their representations to many
  49. major timezones, as well as the ablility to create a DateTime object
  50. in the context of a given timezone.
  51. DateTime objects provide partial numerical behavior:
  52. * Two date-time objects can be subtracted to obtain a time, in days
  53. between the two.
  54. * A date-time object and a positive or negative number may be added to
  55. obtain a new date-time object that is the given number of days later
  56. than the input date-time object.
  57. * A positive or negative number and a date-time object may be added to
  58. obtain a new date-time object that is the given number of days later
  59. than the input date-time object.
  60. * A positive or negative number may be subtracted from a date-time
  61. object to obtain a new date-time object that is the given number of
  62. days earlier than the input date-time object.
  63. DateTime objects may be converted to integer, long, or float numbers
  64. of days since January 1, 1901, using the standard int, long, and float
  65. functions (Compatibility Note: int, long and float return the number
  66. of days since 1901 in GMT rather than local machine timezone).
  67. DateTime objects also provide access to their value in a float format
  68. usable with the python time module, provided that the value of the
  69. object falls in the range of the epoch-based time module.
  70. A DateTime object should be considered immutable; all conversion and numeric
  71. operations return a new DateTime object rather than modify the current object.
  72. A DateTime object always maintains its value as an absolute UTC time,
  73. and is represented in the context of some timezone based on the
  74. arguments used to create the object. A DateTime object's methods
  75. return values based on the timezone context.
  76. Note that in all cases the local machine timezone is used for
  77. representation if no timezone is specified.
  78. Constructor for DateTime
  79. ------------------------
  80. DateTime() returns a new date-time object. DateTimes may be created
  81. with from zero to seven arguments:
  82. * If the function is called with no arguments, then the current date/
  83. time is returned, represented in the timezone of the local machine.
  84. * If the function is invoked with a single string argument which is a
  85. recognized timezone name, an object representing the current time is
  86. returned, represented in the specified timezone.
  87. * If the function is invoked with a single string argument
  88. representing a valid date/time, an object representing that date/
  89. time will be returned.
  90. As a general rule, any date-time representation that is recognized
  91. and unambigous to a resident of North America is acceptable. (The
  92. reason for this qualification is that in North America, a date like:
  93. 2/1/1994 is interpreted as February 1, 1994, while in some parts of
  94. the world, it is interpreted as January 2, 1994.) A date/ time
  95. string consists of two components, a date component and an optional
  96. time component, separated by one or more spaces. If the time
  97. component is omited, 12:00am is assumed.
  98. Any recognized timezone name specified as the final element of the
  99. date/time string will be used for computing the date/time value.
  100. (If you create a DateTime with the string,
  101. "Mar 9, 1997 1:45pm US/Pacific", the value will essentially be the
  102. same as if you had captured time.time() at the specified date and
  103. time on a machine in that timezone). If no timezone is passed, then
  104. the timezone configured on the local machine will be used, **except**
  105. that if the date format matches ISO 8601 ('YYYY-MM-DD'), the instance
  106. will use UTC / CMT+0 as the timezone.
  107. o Returns current date/time, represented in US/Eastern:
  108. >>> from DateTime import DateTime
  109. >>> e = DateTime('US/Eastern')
  110. >>> e.timezone()
  111. 'US/Eastern'
  112. o Returns specified time, represented in local machine zone:
  113. >>> x = DateTime('1997/3/9 1:45pm')
  114. >>> x.parts() # doctest: +ELLIPSIS
  115. (1997, 3, 9, 13, 45, ...)
  116. o Specified time in local machine zone, verbose format:
  117. >>> y = DateTime('Mar 9, 1997 13:45:00')
  118. >>> y.parts() # doctest: +ELLIPSIS
  119. (1997, 3, 9, 13, 45, ...)
  120. >>> y == x
  121. True
  122. o Specified time in UTC via ISO 8601 rule:
  123. >>> z = DateTime('2014-03-24')
  124. >>> z.parts() # doctest: +ELLIPSIS
  125. (2014, 3, 24, 0, 0, ...)
  126. >>> z.timezone()
  127. 'GMT+0'
  128. The date component consists of year, month, and day values. The
  129. year value must be a one-, two-, or four-digit integer. If a one-
  130. or two-digit year is used, the year is assumed to be in the
  131. twentieth century. The month may an integer, from 1 to 12, a month
  132. name, or a month abreviation, where a period may optionally follow
  133. the abreviation. The day must be an integer from 1 to the number of
  134. days in the month. The year, month, and day values may be separated
  135. by periods, hyphens, forward, shashes, or spaces. Extra spaces are
  136. permitted around the delimiters. Year, month, and day values may be
  137. given in any order as long as it is possible to distinguish the
  138. components. If all three components are numbers that are less than
  139. 13, then a a month-day-year ordering is assumed.
  140. The time component consists of hour, minute, and second values
  141. separated by colons. The hour value must be an integer between 0
  142. and 23 inclusively. The minute value must be an integer between 0
  143. and 59 inclusively. The second value may be an integer value
  144. between 0 and 59.999 inclusively. The second value or both the
  145. minute and second values may be ommitted. The time may be followed
  146. by am or pm in upper or lower case, in which case a 12-hour clock is
  147. assumed.
  148. * If the DateTime function is invoked with a single Numeric argument,
  149. the number is assumed to be either a floating point value such as
  150. that returned by time.time() , or a number of days after January 1,
  151. 1901 00:00:00 UTC.
  152. A DateTime object is returned that represents either the gmt value
  153. of the time.time() float represented in the local machine's
  154. timezone, or that number of days after January 1, 1901. Note that
  155. the number of days after 1901 need to be expressed from the
  156. viewpoint of the local machine's timezone. A negative argument will
  157. yield a date-time value before 1901.
  158. * If the function is invoked with two numeric arguments, then the
  159. first is taken to be an integer year and the second argument is
  160. taken to be an offset in days from the beginning of the year, in the
  161. context of the local machine timezone. The date-time value returned
  162. is the given offset number of days from the beginning of the given
  163. year, represented in the timezone of the local machine. The offset
  164. may be positive or negative. Two-digit years are assumed to be in
  165. the twentieth century.
  166. * If the function is invoked with two arguments, the first a float
  167. representing a number of seconds past the epoch in gmt (such as
  168. those returned by time.time()) and the second a string naming a
  169. recognized timezone, a DateTime with a value of that gmt time will
  170. be returned, represented in the given timezone.
  171. >>> import time
  172. >>> t = time.time()
  173. Time t represented as US/Eastern:
  174. >>> now_east = DateTime(t, 'US/Eastern')
  175. Time t represented as US/Pacific:
  176. >>> now_west = DateTime(t, 'US/Pacific')
  177. Only their representations are different:
  178. >>> now_east.equalTo(now_west)
  179. True
  180. * If the function is invoked with three or more numeric arguments,
  181. then the first is taken to be an integer year, the second is taken
  182. to be an integer month, and the third is taken to be an integer day.
  183. If the combination of values is not valid, then a DateTimeError is
  184. raised. One- or two-digit years up to 69 are assumed to be in the
  185. 21st century, whereas values 70-99 are assumed to be 20th century.
  186. The fourth, fifth, and sixth arguments are floating point, positive
  187. or negative offsets in units of hours, minutes, and days, and
  188. default to zero if not given. An optional string may be given as
  189. the final argument to indicate timezone (the effect of this is as if
  190. you had taken the value of time.time() at that time on a machine in
  191. the specified timezone).
  192. If a string argument passed to the DateTime constructor cannot be
  193. parsed, it will raise SyntaxError. Invalid date, time, or
  194. timezone components will raise a DateTimeError.
  195. The module function Timezones() will return a list of the timezones
  196. recognized by the DateTime module. Recognition of timezone names is
  197. case-insensitive.
  198. Instance Methods for DateTime (IDateTime interface)
  199. ---------------------------------------------------
  200. Conversion and comparison methods
  201. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202. * ``timeTime()`` returns the date/time as a floating-point number in
  203. UTC, in the format used by the python time module. Note that it is
  204. possible to create date /time values with DateTime that have no
  205. meaningful value to the time module, and in such cases a
  206. DateTimeError is raised. A DateTime object's value must generally
  207. be between Jan 1, 1970 (or your local machine epoch) and Jan 2038 to
  208. produce a valid time.time() style value.
  209. >>> dt = DateTime('Mar 9, 1997 13:45:00 US/Eastern')
  210. >>> dt.timeTime()
  211. 857933100.0
  212. >>> DateTime('2040/01/01 UTC').timeTime()
  213. 2208988800.0
  214. >>> DateTime('1900/01/01 UTC').timeTime()
  215. -2208988800.0
  216. * ``toZone(z)`` returns a DateTime with the value as the current
  217. object, represented in the indicated timezone:
  218. >>> dt.toZone('UTC')
  219. DateTime('1997/03/09 18:45:00 UTC')
  220. >>> dt.toZone('UTC').equalTo(dt)
  221. True
  222. * ``isFuture()`` returns true if this object represents a date/time
  223. later than the time of the call:
  224. >>> dt.isFuture()
  225. False
  226. >>> DateTime('Jan 1 3000').isFuture() # not time-machine safe!
  227. True
  228. * ``isPast()`` returns true if this object represents a date/time
  229. earlier than the time of the call:
  230. >>> dt.isPast()
  231. True
  232. >>> DateTime('Jan 1 3000').isPast() # not time-machine safe!
  233. False
  234. * ``isCurrentYear()`` returns true if this object represents a
  235. date/time that falls within the current year, in the context of this
  236. object's timezone representation:
  237. >>> dt.isCurrentYear()
  238. False
  239. >>> DateTime().isCurrentYear()
  240. True
  241. * ``isCurrentMonth()`` returns true if this object represents a
  242. date/time that falls within the current month, in the context of
  243. this object's timezone representation:
  244. >>> dt.isCurrentMonth()
  245. False
  246. >>> DateTime().isCurrentMonth()
  247. True
  248. * ``isCurrentDay()`` returns true if this object represents a
  249. date/time that falls within the current day, in the context of this
  250. object's timezone representation:
  251. >>> dt.isCurrentDay()
  252. False
  253. >>> DateTime().isCurrentDay()
  254. True
  255. * ``isCurrentHour()`` returns true if this object represents a
  256. date/time that falls within the current hour, in the context of this
  257. object's timezone representation:
  258. >>> dt.isCurrentHour()
  259. False
  260. >>> DateTime().isCurrentHour()
  261. True
  262. * ``isCurrentMinute()`` returns true if this object represents a
  263. date/time that falls within the current minute, in the context of
  264. this object's timezone representation:
  265. >>> dt.isCurrentMinute()
  266. False
  267. >>> DateTime().isCurrentMinute()
  268. True
  269. * ``isLeapYear()`` returns true if the current year (in the context of
  270. the object's timezone) is a leap year:
  271. >>> dt.isLeapYear()
  272. False
  273. >>> DateTime('Mar 8 2004').isLeapYear()
  274. True
  275. * ``earliestTime()`` returns a new DateTime object that represents the
  276. earliest possible time (in whole seconds) that still falls within
  277. the current object's day, in the object's timezone context:
  278. >>> dt.earliestTime()
  279. DateTime('1997/03/09 00:00:00 US/Eastern')
  280. * ``latestTime()`` return a new DateTime object that represents the
  281. latest possible time (in whole seconds) that still falls within the
  282. current object's day, in the object's timezone context
  283. >>> dt.latestTime()
  284. DateTime('1997/03/09 23:59:59 US/Eastern')
  285. Component access
  286. ~~~~~~~~~~~~~~~~
  287. * ``parts()`` returns a tuple containing the calendar year, month,
  288. day, hour, minute second and timezone of the object
  289. >>> dt.parts() # doctest: +ELLIPSIS
  290. (1997, 3, 9, 13, 45, ... 'US/Eastern')
  291. * ``timezone()`` returns the timezone in which the object is represented:
  292. >>> dt.timezone() in Timezones()
  293. True
  294. * ``tzoffset()`` returns the timezone offset for the objects timezone:
  295. >>> dt.tzoffset()
  296. -18000
  297. * ``year()`` returns the calendar year of the object:
  298. >>> dt.year()
  299. 1997
  300. * ``month()`` retursn the month of the object as an integer:
  301. >>> dt.month()
  302. 3
  303. * ``Month()`` returns the full month name:
  304. >>> dt.Month()
  305. 'March'
  306. * ``aMonth()`` returns the abreviated month name:
  307. >>> dt.aMonth()
  308. 'Mar'
  309. * ``pMonth()`` returns the abreviated (with period) month name:
  310. >>> dt.pMonth()
  311. 'Mar.'
  312. * ``day()`` returns the integer day:
  313. >>> dt.day()
  314. 9
  315. * ``Day()`` returns the full name of the day of the week:
  316. >>> dt.Day()
  317. 'Sunday'
  318. * ``dayOfYear()`` returns the day of the year, in context of the
  319. timezone representation of the object:
  320. >>> dt.dayOfYear()
  321. 68
  322. * ``aDay()`` returns the abreviated name of the day of the week:
  323. >>> dt.aDay()
  324. 'Sun'
  325. * ``pDay()`` returns the abreviated (with period) name of the day of
  326. the week:
  327. >>> dt.pDay()
  328. 'Sun.'
  329. * ``dow()`` returns the integer day of the week, where Sunday is 0:
  330. >>> dt.dow()
  331. 0
  332. * ``dow_1()`` returns the integer day of the week, where sunday is 1:
  333. >>> dt.dow_1()
  334. 1
  335. * ``h_12()`` returns the 12-hour clock representation of the hour:
  336. >>> dt.h_12()
  337. 1
  338. * ``h_24()`` returns the 24-hour clock representation of the hour:
  339. >>> dt.h_24()
  340. 13
  341. * ``ampm()`` returns the appropriate time modifier (am or pm):
  342. >>> dt.ampm()
  343. 'pm'
  344. * ``hour()`` returns the 24-hour clock representation of the hour:
  345. >>> dt.hour()
  346. 13
  347. * ``minute()`` returns the minute:
  348. >>> dt.minute()
  349. 45
  350. * ``second()`` returns the second:
  351. >>> dt.second() == 0
  352. True
  353. * ``millis()`` returns the milliseconds since the epoch in GMT.
  354. >>> dt.millis() == 857933100000
  355. True
  356. strftime()
  357. ~~~~~~~~~~
  358. See ``tests/test_datetime.py``.
  359. General formats from previous DateTime
  360. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361. * ``Date()`` return the date string for the object:
  362. >>> dt.Date()
  363. '1997/03/09'
  364. * ``Time()`` returns the time string for an object to the nearest
  365. second:
  366. >>> dt.Time()
  367. '13:45:00'
  368. * ``TimeMinutes()`` returns the time string for an object not showing
  369. seconds:
  370. >>> dt.TimeMinutes()
  371. '13:45'
  372. * ``AMPM()`` returns the time string for an object to the nearest second:
  373. >>> dt.AMPM()
  374. '01:45:00 pm'
  375. * ``AMPMMinutes()`` returns the time string for an object not showing
  376. seconds:
  377. >>> dt.AMPMMinutes()
  378. '01:45 pm'
  379. * ``PreciseTime()`` returns the time string for the object:
  380. >>> dt.PreciseTime()
  381. '13:45:00.000'
  382. * ``PreciseAMPM()`` returns the time string for the object:
  383. >>> dt.PreciseAMPM()
  384. '01:45:00.000 pm'
  385. * ``yy()`` returns the calendar year as a 2 digit string
  386. >>> dt.yy()
  387. '97'
  388. * ``mm()`` returns the month as a 2 digit string
  389. >>> dt.mm()
  390. '03'
  391. * ``dd()`` returns the day as a 2 digit string:
  392. >>> dt.dd()
  393. '09'
  394. * ``rfc822()`` returns the date in RFC 822 format:
  395. >>> dt.rfc822()
  396. 'Sun, 09 Mar 1997 13:45:00 -0500'
  397. New formats
  398. ~~~~~~~~~~~
  399. * ``fCommon()`` returns a string representing the object's value in
  400. the format: March 9, 1997 1:45 pm:
  401. >>> dt.fCommon()
  402. 'March 9, 1997 1:45 pm'
  403. * ``fCommonZ()`` returns a string representing the object's value in
  404. the format: March 9, 1997 1:45 pm US/Eastern:
  405. >>> dt.fCommonZ()
  406. 'March 9, 1997 1:45 pm US/Eastern'
  407. * ``aCommon()`` returns a string representing the object's value in
  408. the format: Mar 9, 1997 1:45 pm:
  409. >>> dt.aCommon()
  410. 'Mar 9, 1997 1:45 pm'
  411. * ``aCommonZ()`` return a string representing the object's value in
  412. the format: Mar 9, 1997 1:45 pm US/Eastern:
  413. >>> dt.aCommonZ()
  414. 'Mar 9, 1997 1:45 pm US/Eastern'
  415. * ``pCommon()`` returns a string representing the object's value in
  416. the format Mar. 9, 1997 1:45 pm:
  417. >>> dt.pCommon()
  418. 'Mar. 9, 1997 1:45 pm'
  419. * ``pCommonZ()`` returns a string representing the object's value in
  420. the format: Mar. 9, 1997 1:45 pm US/Eastern:
  421. >>> dt.pCommonZ()
  422. 'Mar. 9, 1997 1:45 pm US/Eastern'
  423. * ``ISO()`` returns a string with the date/time in ISO format. Note:
  424. this is not ISO 8601-format! See the ISO8601 and HTML4 methods below
  425. for ISO 8601-compliant output. Dates are output as: YYYY-MM-DD HH:MM:SS
  426. >>> dt.ISO()
  427. '1997-03-09 13:45:00'
  428. * ``ISO8601()`` returns the object in ISO 8601-compatible format
  429. containing the date, time with seconds-precision and the time zone
  430. identifier - see http://www.w3.org/TR/NOTE-datetime. Dates are
  431. output as: YYYY-MM-DDTHH:MM:SSTZD (T is a literal character, TZD is
  432. Time Zone Designator, format +HH:MM or -HH:MM).
  433. The ``HTML4()`` method below offers the same formatting, but
  434. converts to UTC before returning the value and sets the TZD"Z"
  435. >>> dt.ISO8601()
  436. '1997-03-09T13:45:00-05:00'
  437. * ``HTML4()`` returns the object in the format used in the HTML4.0
  438. specification, one of the standard forms in ISO8601. See
  439. http://www.w3.org/TR/NOTE-datetime. Dates are output as:
  440. YYYY-MM-DDTHH:MM:SSZ (T, Z are literal characters, the time is in
  441. UTC.):
  442. >>> dt.HTML4()
  443. '1997-03-09T18:45:00Z'
  444. * ``JulianDay()`` returns the Julian day according to
  445. http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
  446. >>> dt.JulianDay()
  447. 2450517
  448. * ``week()`` returns the week number according to ISO
  449. see http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
  450. >>> dt.week()
  451. 10
  452. Deprecated API
  453. ~~~~~~~~~~~~~~
  454. * DayOfWeek(): see Day()
  455. * Day_(): see pDay()
  456. * Mon(): see aMonth()
  457. * Mon_(): see pMonth
  458. General Services Provided by DateTime
  459. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  460. DateTimes can be repr()'ed; the result will be a string indicating how
  461. to make a DateTime object like this:
  462. >>> repr(dt)
  463. "DateTime('1997/03/09 13:45:00 US/Eastern')"
  464. When we convert them into a string, we get a nicer string that could
  465. actually be shown to a user:
  466. >>> str(dt)
  467. '1997/03/09 13:45:00 US/Eastern'
  468. The hash value of a DateTime is based on the date and time and is
  469. equal for different representations of the DateTime:
  470. >>> hash(dt)
  471. 3618678
  472. >>> hash(dt.toZone('UTC'))
  473. 3618678
  474. DateTime objects can be compared to other DateTime objects OR floating
  475. point numbers such as the ones which are returned by the python time
  476. module by using the equalTo method. Using this API, True is returned if the
  477. object represents a date/time equal to the specified DateTime or time module
  478. style time:
  479. >>> dt.equalTo(dt)
  480. True
  481. >>> dt.equalTo(dt.toZone('UTC'))
  482. True
  483. >>> dt.equalTo(dt.timeTime())
  484. True
  485. >>> dt.equalTo(DateTime())
  486. False
  487. Same goes for inequalities:
  488. >>> dt.notEqualTo(dt)
  489. False
  490. >>> dt.notEqualTo(dt.toZone('UTC'))
  491. False
  492. >>> dt.notEqualTo(dt.timeTime())
  493. False
  494. >>> dt.notEqualTo(DateTime())
  495. True
  496. Normal equality operations only work with datetime objects and take the
  497. timezone setting into account:
  498. >>> dt == dt
  499. True
  500. >>> dt == dt.toZone('UTC')
  501. False
  502. >>> dt == DateTime()
  503. False
  504. >>> dt != dt
  505. False
  506. >>> dt != dt.toZone('UTC')
  507. True
  508. >>> dt != DateTime()
  509. True
  510. But the other comparison operations compare the referenced moment in time and
  511. not the representation itself:
  512. >>> dt > dt
  513. False
  514. >>> DateTime() > dt
  515. True
  516. >>> dt > DateTime().timeTime()
  517. False
  518. >>> DateTime().timeTime() > dt
  519. True
  520. >>> dt.greaterThan(dt)
  521. False
  522. >>> DateTime().greaterThan(dt)
  523. True
  524. >>> dt.greaterThan(DateTime().timeTime())
  525. False
  526. >>> dt >= dt
  527. True
  528. >>> DateTime() >= dt
  529. True
  530. >>> dt >= DateTime().timeTime()
  531. False
  532. >>> DateTime().timeTime() >= dt
  533. True
  534. >>> dt.greaterThanEqualTo(dt)
  535. True
  536. >>> DateTime().greaterThanEqualTo(dt)
  537. True
  538. >>> dt.greaterThanEqualTo(DateTime().timeTime())
  539. False
  540. >>> dt < dt
  541. False
  542. >>> DateTime() < dt
  543. False
  544. >>> dt < DateTime().timeTime()
  545. True
  546. >>> DateTime().timeTime() < dt
  547. False
  548. >>> dt.lessThan(dt)
  549. False
  550. >>> DateTime().lessThan(dt)
  551. False
  552. >>> dt.lessThan(DateTime().timeTime())
  553. True
  554. >>> dt <= dt
  555. True
  556. >>> DateTime() <= dt
  557. False
  558. >>> dt <= DateTime().timeTime()
  559. True
  560. >>> DateTime().timeTime() <= dt
  561. False
  562. >>> dt.lessThanEqualTo(dt)
  563. True
  564. >>> DateTime().lessThanEqualTo(dt)
  565. False
  566. >>> dt.lessThanEqualTo(DateTime().timeTime())
  567. True
  568. Numeric Services Provided by DateTime
  569. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  570. A DateTime may be added to a number and a number may be added to a
  571. DateTime:
  572. >>> dt + 5
  573. DateTime('1997/03/14 13:45:00 US/Eastern')
  574. >>> 5 + dt
  575. DateTime('1997/03/14 13:45:00 US/Eastern')
  576. Two DateTimes cannot be added:
  577. >>> from DateTime.interfaces import DateTimeError
  578. >>> try:
  579. ... dt + dt
  580. ... print('fail')
  581. ... except DateTimeError:
  582. ... print('ok')
  583. ok
  584. Either a DateTime or a number may be subtracted from a DateTime,
  585. however, a DateTime may not be subtracted from a number:
  586. >>> DateTime('1997/03/10 13:45 US/Eastern') - dt
  587. 1.0
  588. >>> dt - 1
  589. DateTime('1997/03/08 13:45:00 US/Eastern')
  590. >>> 1 - dt
  591. Traceback (most recent call last):
  592. ...
  593. TypeError: unsupported operand type(s) for -: 'int' and 'DateTime'
  594. DateTimes can also be converted to integers (number of seconds since
  595. the epoch) and floats:
  596. >>> int(dt)
  597. 857933100
  598. >>> float(dt)
  599. 857933100.0
  600. Changelog
  601. =========
  602. 4.3 (2018-10-05)
  603. ----------------
  604. - Add support for Python 3.7.
  605. 4.2 (2017-04-26)
  606. ----------------
  607. - Add support for Python 3.6, drop support for Python 3.3.
  608. 4.1.1 (2016-04-30)
  609. ------------------
  610. - Support unpickling instances having a numeric timezone like `+0430`.
  611. 4.1 (2016-04-03)
  612. ----------------
  613. - Add support for Python 3.4 and 3.5.
  614. - Drop support for Python 2.6 and 3.2.
  615. 4.0.1 (2013-10-15)
  616. ------------------
  617. - Provide more backward compatible timezones.
  618. [vangheem]
  619. 4.0 (2013-02-23)
  620. ----------------
  621. - Added support for Python 3.2 and 3.3 in addition to 2.6 and 2.7.
  622. - Removed unused legacy pytz tests and the DateTimeZone module and renamed
  623. some test internals.
  624. 3.0.3 (2013-01-22)
  625. ------------------
  626. - Allow timezone argument to be a Unicode string while creating a DateTime
  627. object using two arguments.
  628. 3.0.2 (2012-10-21)
  629. ------------------
  630. - LP #1045233: Respect date format setting for parsing dates like `11-01-2001`.
  631. 3.0.1 (2012-09-23)
  632. ------------------
  633. - Add `_dt_reconstructor` function introduced in DateTime 2.12.7 to provide
  634. forward compatibility with pickles that might reference this function.
  635. 3.0 (2011-12-09)
  636. ----------------
  637. - No changes.
  638. Backwards compatibility of DateTime 3
  639. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  640. DateTime 3 changes its pickle representation. DateTime instances pickled with
  641. former versions of DateTime can be read, but older DateTime versions cannot read
  642. DateTime instances pickled with version 3.
  643. DateTime 3 changes DateTime to be a new-style class with slots instead of being
  644. an old-style class.
  645. DateTime 3 tries to preserve microsecond resolution throughout most of its API's
  646. while former versions were often only accurate to millisecond resolution. Due to
  647. the representation of float values in Python versions before Python 2.7 you
  648. shouldn't compare string or float representations of DateTime instances if you
  649. want high accuracy. The same is true for calculated values returned by methods
  650. like `timeTime()`. You get the highest accuracy of comparing DateTime values by
  651. calling its `micros()` methods. DateTime is not particular well suited to be
  652. used in comparing timestamps of file systems - use the time and datetime objects
  653. from the Python standard library instead.
  654. 3.0b3 (2011-10-19)
  655. ------------------
  656. - Allow comparison of DateTime objects against None.
  657. 3.0b2 (2011-10-19)
  658. ------------------
  659. - Reverted the single argument `None` special case handling for unpickling and
  660. continue to treat it as meaning `now`.
  661. 3.0b1 (2011-05-07)
  662. ------------------
  663. - Restored `strftimeFormatter` as a class.
  664. - Added tests for read-only class attributes and interface.
  665. 3.0a2 (2011-05-07)
  666. ------------------
  667. - Added back support for reading old DateTime pickles without a `_micros` value.
  668. - Avoid storing `_t` representing the time as a float in seconds since the
  669. epoch, as we already have `_micros` doing the same as a long. Memory use is
  670. down to about 300 bytes per DateTime instance.
  671. - Updated exception raising syntax to current style.
  672. - Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon`, `_pmon`, `_pmhour`
  673. and `_pm` in memory for every instance but look them up dynamically based on
  674. `_dayoffset`, `_month` and `_hour`. This saves another 150 bytes of memory
  675. per DateTime instance.
  676. - Moved various internal parsing related class variables to module constants.
  677. - No longer provide the `DateError`, `DateTimeError`, `SyntaxError` and
  678. `TimeError` exceptions as class attributes, import them from their canonical
  679. `DateTime.interfaces` location instead.
  680. - Removed deprecated `_isDST` and `_localzone` class variables.
  681. - Moved pytz cache from `DateTime._tzinfo` to a module global `_TZINFO`.
  682. - Make DateTime a new-style class and limit its available attributes via a
  683. slots definition. The pickle size increases to 110 bytes thanks to the
  684. `ccopy_reg\n_reconstructor` stanza. But the memory size drops from 3kb to
  685. 500 bytes for each instance.
  686. 3.0a1 (2011-05-06)
  687. ------------------
  688. - Reordered some calculations in `_calcIndependentSecondEtc` to preserve more
  689. floating point precision.
  690. - Optimized the pickled data, by only storing a tuple of `_micros` and time
  691. zone information - this reduces the pickle size from an average of 300 bytes
  692. to just 60 bytes.
  693. - Optimized un-pickling, by avoiding the creation of an intermediate DateTime
  694. value representing the current time.
  695. - Removed in-place migration of old DateTime pickles without a `_micros` value.
  696. - Removed deprecated support for using `DateTime.__cmp__`.
  697. - Take time zone settings into account when comparing two date times for
  698. (non-) equality.
  699. - Fixed (possibly unused) _parse_iso8601 function.
  700. - Removed unused import of legacy DateTimeZone, strftime and re.
  701. Remove trailing whitespace.
  702. - Removed reference to missing version section from buildout.
  703. 2.12.7 (2012-08-11)
  704. -------------------
  705. - Added forward compatibility with DateTime 3 pickle format. DateTime
  706. instances constructed under version 3 can be read and unpickled by this
  707. version. The pickled data is converted to the current versions format
  708. (old-style class / no slots). Once converted it will be stored again in the
  709. old format. This should allow for a transparent upgrade/downgrade path
  710. between DateTime 2 and 3.
  711. 2.12.6 (2010-10-17)
  712. -------------------
  713. - Changed ``testDayOfWeek`` test to be independent of OS locale.
  714. 2.12.5 (2010-07-29)
  715. -------------------
  716. - Launchpad #143269: Corrected the documentation for year value
  717. behavior when constructing a DateTime object with three numeric
  718. arguments.
  719. - Launchpad #142521: Removed confusing special case in
  720. DateTime.__str__ where DateTime instances for midnight
  721. (e.g. '2010-07-27 00:00:00 US/Eastern') values would
  722. render only their date and nothing else.
  723. 2.12.4 (2010-07-12)
  724. -------------------
  725. - Fixed mapping of EDT (was -> 'GMT-0400', now 'GMT-4').
  726. 2.12.3 (2010-07-09)
  727. -------------------
  728. - Added EDT timezone support. Addresses bug #599856.
  729. [vangheem]
  730. 2.12.2 (2010-05-05)
  731. -------------------
  732. - Launchpad #572715: Relaxed pin on pytz, after applying a patch from
  733. Marius Gedminus which fixes the apparent API breakage.
  734. 2.12.1 (2010-04-30)
  735. -------------------
  736. - Removed an undeclared testing dependency on zope.testing.doctest in favor of
  737. the standard libraries doctest module.
  738. - Added a maximum version requirement on pytz <= 2010b. Later versions produce
  739. test failures related to timezone changes.
  740. 2.12.0 (2009-03-04)
  741. -------------------
  742. - Launchpad #290254: Forward-ported fix for '_micros'-less pickles from
  743. the Zope 2.11 branch version.
  744. 2.11.2 (2009-02-02)
  745. -------------------
  746. - Include *all* pytz zone names, not just "common" ones.
  747. - Fix one fragile doctest, band-aid another.
  748. - Fix for launchpad #267545: DateTime(DateTime()) should preserve the
  749. correct hour.
  750. 2.11.1 (2008-08-05)
  751. -------------------
  752. - DateTime conversion of datetime objects with non-pytz tzinfo. Timezones()
  753. returns a copy of the timezone list (allows tests to run).
  754. - Merged the slinkp-datetime-200007 branch: fix the DateTime(anotherDateTime)
  755. constructor to preserve timezones.
  756. 2.11.0b1 (2008-01-06)
  757. ---------------------
  758. - Split off from the Zope2 main source code tree.