blob: b0d9e07ba89d06f0223d2cba94469ded753b9bdb [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`time` --- Time access and conversions
2===========================================
3
4.. module:: time
5 :synopsis: Time access and conversions.
6
7
8This module provides various time-related functions. For related
9functionality, see also the :mod:`datetime` and :mod:`calendar` modules.
10
11Although this module is always available,
12not all functions are available on all platforms. Most of the functions
13defined in this module call platform C library functions with the same name. It
14may sometimes be helpful to consult the platform documentation, because the
15semantics of these functions varies among platforms.
16
17An explanation of some terminology and conventions is in order.
18
Georg Brandlb67878a2010-10-15 17:01:15 +000019.. index:: single: epoch
Georg Brandl116aa622007-08-15 14:28:22 +000020
21* The :dfn:`epoch` is the point where the time starts. On January 1st of that
22 year, at 0 hours, the "time since the epoch" is zero. For Unix, the epoch is
23 1970. To find out what the epoch is, look at ``gmtime(0)``.
24
Georg Brandlb67878a2010-10-15 17:01:15 +000025.. index:: single: Year 2038
Georg Brandl116aa622007-08-15 14:28:22 +000026
27* The functions in this module do not handle dates and times before the epoch or
28 far in the future. The cut-off point in the future is determined by the C
29 library; for Unix, it is typically in 2038.
30
Georg Brandlb67878a2010-10-15 17:01:15 +000031.. index::
32 single: Year 2000
33 single: Y2K
34
35.. _time-y2kissues:
Georg Brandl116aa622007-08-15 14:28:22 +000036
37* **Year 2000 (Y2K) issues**: Python depends on the platform's C library, which
38 generally doesn't have year 2000 issues, since all dates and times are
39 represented internally as seconds since the epoch. Functions accepting a
40 :class:`struct_time` (see below) generally require a 4-digit year. For backward
41 compatibility, 2-digit years are supported if the module variable
42 ``accept2dyear`` is a non-zero integer; this variable is initialized to ``1``
43 unless the environment variable :envvar:`PYTHONY2K` is set to a non-empty
44 string, in which case it is initialized to ``0``. Thus, you can set
45 :envvar:`PYTHONY2K` to a non-empty string in the environment to require 4-digit
46 years for all year input. When 2-digit years are accepted, they are converted
47 according to the POSIX or X/Open standard: values 69-99 are mapped to 1969-1999,
48 and values 0--68 are mapped to 2000--2068. Values 100--1899 are always illegal.
49 Note that this is new as of Python 1.5.2(a2); earlier versions, up to Python
50 1.5.1 and 1.5.2a1, would add 1900 to year values below 1900.
51
Georg Brandlb67878a2010-10-15 17:01:15 +000052.. index::
53 single: UTC
54 single: Coordinated Universal Time
55 single: Greenwich Mean Time
Georg Brandl116aa622007-08-15 14:28:22 +000056
57* UTC is Coordinated Universal Time (formerly known as Greenwich Mean Time, or
58 GMT). The acronym UTC is not a mistake but a compromise between English and
59 French.
60
Georg Brandlb67878a2010-10-15 17:01:15 +000061.. index:: single: Daylight Saving Time
Georg Brandl116aa622007-08-15 14:28:22 +000062
63* DST is Daylight Saving Time, an adjustment of the timezone by (usually) one
64 hour during part of the year. DST rules are magic (determined by local law) and
65 can change from year to year. The C library has a table containing the local
66 rules (often it is read from a system file for flexibility) and is the only
67 source of True Wisdom in this respect.
68
69* The precision of the various real-time functions may be less than suggested by
70 the units in which their value or argument is expressed. E.g. on most Unix
Georg Brandlc575c902008-09-13 17:46:05 +000071 systems, the clock "ticks" only 50 or 100 times a second.
Georg Brandl116aa622007-08-15 14:28:22 +000072
73* On the other hand, the precision of :func:`time` and :func:`sleep` is better
74 than their Unix equivalents: times are expressed as floating point numbers,
75 :func:`time` returns the most accurate time available (using Unix
Georg Brandl60203b42010-10-06 10:11:56 +000076 :c:func:`gettimeofday` where available), and :func:`sleep` will accept a time
77 with a nonzero fraction (Unix :c:func:`select` is used to implement this, where
Georg Brandl116aa622007-08-15 14:28:22 +000078 available).
79
80* The time value as returned by :func:`gmtime`, :func:`localtime`, and
81 :func:`strptime`, and accepted by :func:`asctime`, :func:`mktime` and
82 :func:`strftime`, is a sequence of 9 integers. The return values of
83 :func:`gmtime`, :func:`localtime`, and :func:`strptime` also offer attribute
84 names for individual fields.
85
Georg Brandlb67878a2010-10-15 17:01:15 +000086 See :class:`struct_time` for a description of these objects.
Georg Brandl116aa622007-08-15 14:28:22 +000087
Benjamin Petersone0124bd2009-03-09 21:04:33 +000088* Use the following functions to convert between time representations:
89
90 +-------------------------+-------------------------+-------------------------+
91 | From | To | Use |
92 +=========================+=========================+=========================+
93 | seconds since the epoch | :class:`struct_time` in | :func:`gmtime` |
94 | | UTC | |
95 +-------------------------+-------------------------+-------------------------+
96 | seconds since the epoch | :class:`struct_time` in | :func:`localtime` |
97 | | local time | |
98 +-------------------------+-------------------------+-------------------------+
99 | :class:`struct_time` in | seconds since the epoch | :func:`calendar.timegm` |
100 | UTC | | |
101 +-------------------------+-------------------------+-------------------------+
102 | :class:`struct_time` in | seconds since the epoch | :func:`mktime` |
103 | local time | | |
104 +-------------------------+-------------------------+-------------------------+
105
106
Georg Brandl116aa622007-08-15 14:28:22 +0000107The module defines the following functions and data items:
108
109
110.. data:: accept2dyear
111
112 Boolean value indicating whether two-digit year values will be accepted. This
113 is true by default, but will be set to false if the environment variable
114 :envvar:`PYTHONY2K` has been set to a non-empty string. It may also be modified
115 at run time.
116
117
118.. data:: altzone
119
120 The offset of the local DST timezone, in seconds west of UTC, if one is defined.
121 This is negative if the local DST timezone is east of UTC (as in Western Europe,
122 including the UK). Only use this if ``daylight`` is nonzero.
123
124
125.. function:: asctime([t])
126
127 Convert a tuple or :class:`struct_time` representing a time as returned by
Alexander Belopolskyb9588b52011-01-04 16:34:30 +0000128 :func:`gmtime` or :func:`localtime` to a string of the following
Georg Brandl116aa622007-08-15 14:28:22 +0000129 form: ``'Sun Jun 20 23:21:05 1993'``. If *t* is not provided, the current time
130 as returned by :func:`localtime` is used. Locale information is not used by
131 :func:`asctime`.
132
133 .. note::
134
135 Unlike the C function of the same name, there is no trailing newline.
136
Georg Brandl116aa622007-08-15 14:28:22 +0000137
138.. function:: clock()
139
140 .. index::
141 single: CPU time
142 single: processor time
143 single: benchmarking
144
145 On Unix, return the current processor time as a floating point number expressed
146 in seconds. The precision, and in fact the very definition of the meaning of
147 "processor time", depends on that of the C function of the same name, but in any
148 case, this is the function to use for benchmarking Python or timing algorithms.
149
150 On Windows, this function returns wall-clock seconds elapsed since the first
151 call to this function, as a floating point number, based on the Win32 function
Georg Brandl60203b42010-10-06 10:11:56 +0000152 :c:func:`QueryPerformanceCounter`. The resolution is typically better than one
Georg Brandl116aa622007-08-15 14:28:22 +0000153 microsecond.
154
155
156.. function:: ctime([secs])
157
158 Convert a time expressed in seconds since the epoch to a string representing
159 local time. If *secs* is not provided or :const:`None`, the current time as
160 returned by :func:`time` is used. ``ctime(secs)`` is equivalent to
161 ``asctime(localtime(secs))``. Locale information is not used by :func:`ctime`.
162
Georg Brandl116aa622007-08-15 14:28:22 +0000163
164.. data:: daylight
165
166 Nonzero if a DST timezone is defined.
167
168
169.. function:: gmtime([secs])
170
171 Convert a time expressed in seconds since the epoch to a :class:`struct_time` in
172 UTC in which the dst flag is always zero. If *secs* is not provided or
173 :const:`None`, the current time as returned by :func:`time` is used. Fractions
174 of a second are ignored. See above for a description of the
175 :class:`struct_time` object. See :func:`calendar.timegm` for the inverse of this
176 function.
177
Georg Brandl116aa622007-08-15 14:28:22 +0000178
179.. function:: localtime([secs])
180
181 Like :func:`gmtime` but converts to local time. If *secs* is not provided or
182 :const:`None`, the current time as returned by :func:`time` is used. The dst
183 flag is set to ``1`` when DST applies to the given time.
184
Georg Brandl116aa622007-08-15 14:28:22 +0000185
186.. function:: mktime(t)
187
188 This is the inverse function of :func:`localtime`. Its argument is the
189 :class:`struct_time` or full 9-tuple (since the dst flag is needed; use ``-1``
190 as the dst flag if it is unknown) which expresses the time in *local* time, not
191 UTC. It returns a floating point number, for compatibility with :func:`time`.
192 If the input value cannot be represented as a valid time, either
193 :exc:`OverflowError` or :exc:`ValueError` will be raised (which depends on
194 whether the invalid value is caught by Python or the underlying C libraries).
195 The earliest date for which it can generate a time is platform-dependent.
196
197
198.. function:: sleep(secs)
199
200 Suspend execution for the given number of seconds. The argument may be a
201 floating point number to indicate a more precise sleep time. The actual
202 suspension time may be less than that requested because any caught signal will
203 terminate the :func:`sleep` following execution of that signal's catching
204 routine. Also, the suspension time may be longer than requested by an arbitrary
205 amount because of the scheduling of other activity in the system.
206
207
208.. function:: strftime(format[, t])
209
210 Convert a tuple or :class:`struct_time` representing a time as returned by
211 :func:`gmtime` or :func:`localtime` to a string as specified by the *format*
212 argument. If *t* is not provided, the current time as returned by
213 :func:`localtime` is used. *format* must be a string. :exc:`ValueError` is
214 raised if any field in *t* is outside of the allowed range.
215
Georg Brandl55ac8f02007-09-01 13:51:09 +0000216 0 is a legal argument for any position in the time tuple; if it is normally
217 illegal the value is forced to a correct one.
Georg Brandl116aa622007-08-15 14:28:22 +0000218
219 The following directives can be embedded in the *format* string. They are shown
220 without the optional field width and precision specification, and are replaced
221 by the indicated characters in the :func:`strftime` result:
222
Georg Brandl55ac8f02007-09-01 13:51:09 +0000223 +-----------+------------------------------------------------+-------+
224 | Directive | Meaning | Notes |
225 +===========+================================================+=======+
226 | ``%a`` | Locale's abbreviated weekday name. | |
227 | | | |
228 +-----------+------------------------------------------------+-------+
229 | ``%A`` | Locale's full weekday name. | |
230 +-----------+------------------------------------------------+-------+
231 | ``%b`` | Locale's abbreviated month name. | |
232 | | | |
233 +-----------+------------------------------------------------+-------+
234 | ``%B`` | Locale's full month name. | |
235 +-----------+------------------------------------------------+-------+
236 | ``%c`` | Locale's appropriate date and time | |
237 | | representation. | |
238 +-----------+------------------------------------------------+-------+
239 | ``%d`` | Day of the month as a decimal number [01,31]. | |
240 | | | |
241 +-----------+------------------------------------------------+-------+
242 | ``%H`` | Hour (24-hour clock) as a decimal number | |
243 | | [00,23]. | |
244 +-----------+------------------------------------------------+-------+
245 | ``%I`` | Hour (12-hour clock) as a decimal number | |
246 | | [01,12]. | |
247 +-----------+------------------------------------------------+-------+
248 | ``%j`` | Day of the year as a decimal number [001,366]. | |
249 | | | |
250 +-----------+------------------------------------------------+-------+
251 | ``%m`` | Month as a decimal number [01,12]. | |
252 | | | |
253 +-----------+------------------------------------------------+-------+
254 | ``%M`` | Minute as a decimal number [00,59]. | |
255 | | | |
256 +-----------+------------------------------------------------+-------+
257 | ``%p`` | Locale's equivalent of either AM or PM. | \(1) |
258 | | | |
259 +-----------+------------------------------------------------+-------+
260 | ``%S`` | Second as a decimal number [00,61]. | \(2) |
261 | | | |
262 +-----------+------------------------------------------------+-------+
263 | ``%U`` | Week number of the year (Sunday as the first | \(3) |
264 | | day of the week) as a decimal number [00,53]. | |
265 | | All days in a new year preceding the first | |
266 | | Sunday are considered to be in week 0. | |
267 | | | |
268 | | | |
269 | | | |
270 +-----------+------------------------------------------------+-------+
271 | ``%w`` | Weekday as a decimal number [0(Sunday),6]. | |
272 | | | |
273 +-----------+------------------------------------------------+-------+
274 | ``%W`` | Week number of the year (Monday as the first | \(3) |
275 | | day of the week) as a decimal number [00,53]. | |
276 | | All days in a new year preceding the first | |
277 | | Monday are considered to be in week 0. | |
278 | | | |
279 | | | |
280 | | | |
281 +-----------+------------------------------------------------+-------+
282 | ``%x`` | Locale's appropriate date representation. | |
283 | | | |
284 +-----------+------------------------------------------------+-------+
285 | ``%X`` | Locale's appropriate time representation. | |
286 | | | |
287 +-----------+------------------------------------------------+-------+
288 | ``%y`` | Year without century as a decimal number | |
289 | | [00,99]. | |
290 +-----------+------------------------------------------------+-------+
291 | ``%Y`` | Year with century as a decimal number. | |
292 | | | |
293 +-----------+------------------------------------------------+-------+
294 | ``%Z`` | Time zone name (no characters if no time zone | |
295 | | exists). | |
296 +-----------+------------------------------------------------+-------+
297 | ``%%`` | A literal ``'%'`` character. | |
298 +-----------+------------------------------------------------+-------+
Georg Brandl116aa622007-08-15 14:28:22 +0000299
300 Notes:
301
302 (1)
303 When used with the :func:`strptime` function, the ``%p`` directive only affects
304 the output hour field if the ``%I`` directive is used to parse the hour.
305
306 (2)
307 The range really is ``0`` to ``61``; this accounts for leap seconds and the
308 (very rare) double leap seconds.
309
310 (3)
311 When used with the :func:`strptime` function, ``%U`` and ``%W`` are only used in
312 calculations when the day of the week and the year are specified.
313
314 Here is an example, a format for dates compatible with that specified in the
315 :rfc:`2822` Internet email standard. [#]_ ::
316
317 >>> from time import gmtime, strftime
318 >>> strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())
319 'Thu, 28 Jun 2001 14:17:15 +0000'
320
321 Additional directives may be supported on certain platforms, but only the ones
322 listed here have a meaning standardized by ANSI C.
323
324 On some platforms, an optional field width and precision specification can
325 immediately follow the initial ``'%'`` of a directive in the following order;
326 this is also not portable. The field width is normally 2 except for ``%j`` where
327 it is 3.
328
329
330.. function:: strptime(string[, format])
331
Brett Cannon7f6b4f82009-03-30 21:30:26 +0000332 Parse a string representing a time according to a format. The return value
333 is a :class:`struct_time` as returned by :func:`gmtime` or
334 :func:`localtime`.
Georg Brandl116aa622007-08-15 14:28:22 +0000335
336 The *format* parameter uses the same directives as those used by
337 :func:`strftime`; it defaults to ``"%a %b %d %H:%M:%S %Y"`` which matches the
Brett Cannon7f6b4f82009-03-30 21:30:26 +0000338 formatting returned by :func:`ctime`. If *string* cannot be parsed according
339 to *format*, or if it has excess data after parsing, :exc:`ValueError` is
340 raised. The default values used to fill in any missing data when more
341 accurate values cannot be inferred are ``(1900, 1, 1, 0, 0, 0, 0, 1, -1)``.
342 Both *string* and *format* must be strings.
Georg Brandl116aa622007-08-15 14:28:22 +0000343
Christian Heimesfe337bf2008-03-23 21:54:12 +0000344 For example:
Georg Brandl116aa622007-08-15 14:28:22 +0000345
346 >>> import time
Christian Heimesfe337bf2008-03-23 21:54:12 +0000347 >>> time.strptime("30 Nov 00", "%d %b %y") # doctest: +NORMALIZE_WHITESPACE
348 time.struct_time(tm_year=2000, tm_mon=11, tm_mday=30, tm_hour=0, tm_min=0,
349 tm_sec=0, tm_wday=3, tm_yday=335, tm_isdst=-1)
Georg Brandl116aa622007-08-15 14:28:22 +0000350
351 Support for the ``%Z`` directive is based on the values contained in ``tzname``
352 and whether ``daylight`` is true. Because of this, it is platform-specific
353 except for recognizing UTC and GMT which are always known (and are considered to
354 be non-daylight savings timezones).
355
356 Only the directives specified in the documentation are supported. Because
357 ``strftime()`` is implemented per platform it can sometimes offer more
358 directives than those listed. But ``strptime()`` is independent of any platform
359 and thus does not necessarily support all directives available that are not
360 documented as supported.
361
362
Georg Brandlb67878a2010-10-15 17:01:15 +0000363.. class:: struct_time
Georg Brandl116aa622007-08-15 14:28:22 +0000364
365 The type of the time value sequence returned by :func:`gmtime`,
Georg Brandlb67878a2010-10-15 17:01:15 +0000366 :func:`localtime`, and :func:`strptime`. It is an object with a :term:`named
367 tuple` interface: values can be accessed by index and by attribute name. The
368 following values are present:
369
370 +-------+-------------------+---------------------------------+
371 | Index | Attribute | Values |
372 +=======+===================+=================================+
373 | 0 | :attr:`tm_year` | (for example, 1993) |
374 +-------+-------------------+---------------------------------+
375 | 1 | :attr:`tm_mon` | range [1, 12] |
376 +-------+-------------------+---------------------------------+
377 | 2 | :attr:`tm_mday` | range [1, 31] |
378 +-------+-------------------+---------------------------------+
379 | 3 | :attr:`tm_hour` | range [0, 23] |
380 +-------+-------------------+---------------------------------+
381 | 4 | :attr:`tm_min` | range [0, 59] |
382 +-------+-------------------+---------------------------------+
383 | 5 | :attr:`tm_sec` | range [0, 61]; see **(1)** in |
384 | | | :func:`strftime` description |
385 +-------+-------------------+---------------------------------+
386 | 6 | :attr:`tm_wday` | range [0, 6], Monday is 0 |
387 +-------+-------------------+---------------------------------+
388 | 7 | :attr:`tm_yday` | range [1, 366] |
389 +-------+-------------------+---------------------------------+
390 | 8 | :attr:`tm_isdst` | 0, 1 or -1; see below |
391 +-------+-------------------+---------------------------------+
392
393 Note that unlike the C structure, the month value is a range of [1, 12], not
394 [0, 11]. A year value will be handled as described under :ref:`Year 2000
395 (Y2K) issues <time-y2kissues>` above. A ``-1`` argument as the daylight
396 savings flag, passed to :func:`mktime` will usually result in the correct
397 daylight savings state to be filled in.
398
399 When a tuple with an incorrect length is passed to a function expecting a
400 :class:`struct_time`, or having elements of the wrong type, a
401 :exc:`TypeError` is raised.
Georg Brandl116aa622007-08-15 14:28:22 +0000402
Georg Brandl116aa622007-08-15 14:28:22 +0000403
404.. function:: time()
405
406 Return the time as a floating point number expressed in seconds since the epoch,
407 in UTC. Note that even though the time is always returned as a floating point
408 number, not all systems provide time with a better precision than 1 second.
409 While this function normally returns non-decreasing values, it can return a
410 lower value than a previous call if the system clock has been set back between
411 the two calls.
412
413
414.. data:: timezone
415
416 The offset of the local (non-DST) timezone, in seconds west of UTC (negative in
417 most of Western Europe, positive in the US, zero in the UK).
418
419
420.. data:: tzname
421
422 A tuple of two strings: the first is the name of the local non-DST timezone, the
423 second is the name of the local DST timezone. If no DST timezone is defined,
424 the second string should not be used.
425
426
427.. function:: tzset()
428
429 Resets the time conversion rules used by the library routines. The environment
430 variable :envvar:`TZ` specifies how this is done.
431
Georg Brandl116aa622007-08-15 14:28:22 +0000432 Availability: Unix.
433
434 .. note::
435
436 Although in many cases, changing the :envvar:`TZ` environment variable may
437 affect the output of functions like :func:`localtime` without calling
438 :func:`tzset`, this behavior should not be relied on.
439
440 The :envvar:`TZ` environment variable should contain no whitespace.
441
442 The standard format of the :envvar:`TZ` environment variable is (whitespace
443 added for clarity)::
444
445 std offset [dst [offset [,start[/time], end[/time]]]]
446
447 Where the components are:
448
449 ``std`` and ``dst``
450 Three or more alphanumerics giving the timezone abbreviations. These will be
451 propagated into time.tzname
452
453 ``offset``
454 The offset has the form: ``± hh[:mm[:ss]]``. This indicates the value
455 added the local time to arrive at UTC. If preceded by a '-', the timezone
456 is east of the Prime Meridian; otherwise, it is west. If no offset follows
457 dst, summer time is assumed to be one hour ahead of standard time.
458
459 ``start[/time], end[/time]``
460 Indicates when to change to and back from DST. The format of the
461 start and end dates are one of the following:
462
463 :samp:`J{n}`
464 The Julian day *n* (1 <= *n* <= 365). Leap days are not counted, so in
465 all years February 28 is day 59 and March 1 is day 60.
466
467 :samp:`{n}`
468 The zero-based Julian day (0 <= *n* <= 365). Leap days are counted, and
469 it is possible to refer to February 29.
470
471 :samp:`M{m}.{n}.{d}`
472 The *d*'th day (0 <= *d* <= 6) or week *n* of month *m* of the year (1
473 <= *n* <= 5, 1 <= *m* <= 12, where week 5 means "the last *d* day in
474 month *m*" which may occur in either the fourth or the fifth
475 week). Week 1 is the first week in which the *d*'th day occurs. Day
476 zero is Sunday.
477
478 ``time`` has the same format as ``offset`` except that no leading sign
479 ('-' or '+') is allowed. The default, if time is not given, is 02:00:00.
480
481 ::
482
483 >>> os.environ['TZ'] = 'EST+05EDT,M4.1.0,M10.5.0'
484 >>> time.tzset()
485 >>> time.strftime('%X %x %Z')
486 '02:07:36 05/08/03 EDT'
487 >>> os.environ['TZ'] = 'AEST-10AEDT-11,M10.5.0,M3.5.0'
488 >>> time.tzset()
489 >>> time.strftime('%X %x %Z')
490 '16:08:12 05/08/03 AEST'
491
492 On many Unix systems (including \*BSD, Linux, Solaris, and Darwin), it is more
493 convenient to use the system's zoneinfo (:manpage:`tzfile(5)`) database to
494 specify the timezone rules. To do this, set the :envvar:`TZ` environment
495 variable to the path of the required timezone datafile, relative to the root of
496 the systems 'zoneinfo' timezone database, usually located at
497 :file:`/usr/share/zoneinfo`. For example, ``'US/Eastern'``,
498 ``'Australia/Melbourne'``, ``'Egypt'`` or ``'Europe/Amsterdam'``. ::
499
500 >>> os.environ['TZ'] = 'US/Eastern'
501 >>> time.tzset()
502 >>> time.tzname
503 ('EST', 'EDT')
504 >>> os.environ['TZ'] = 'Egypt'
505 >>> time.tzset()
506 >>> time.tzname
507 ('EET', 'EEST')
508
509
510.. seealso::
511
512 Module :mod:`datetime`
513 More object-oriented interface to dates and times.
514
515 Module :mod:`locale`
516 Internationalization services. The locale settings can affect the return values
517 for some of the functions in the :mod:`time` module.
518
519 Module :mod:`calendar`
520 General calendar-related functions. :func:`timegm` is the inverse of
521 :func:`gmtime` from this module.
522
523.. rubric:: Footnotes
524
525.. [#] The use of ``%Z`` is now deprecated, but the ``%z`` escape that expands to the
526 preferred hour/minute offset is not supported by all ANSI C libraries. Also, a
527 strict reading of the original 1982 :rfc:`822` standard calls for a two-digit
528 year (%y rather than %Y), but practice moved to 4-digit years long before the
529 year 2000. The 4-digit year has been mandated by :rfc:`2822`, which obsoletes
530 :rfc:`822`.
531