If 'local' is non-zero, it produces a string in local time with a +-#### timezone offset, otherwise it uses timezone Z (UTC).
'base' restricts the output to that unit. Set 'base' to -1 to auto-detect a base after which all the values are zero. <blockquote>
'tzoffset' is used if 'local' is enabled, and 'tzoffset' is set to a value other than -1. This is a manual override for the local time zone to use, as an offset in minutes.
'casting' controls whether data loss is allowed by truncating the data to a coarser unit. This interacts with 'local', slightly, in order to form a date unit string as a local time, the casting must be unsafe.
Returns 0 on success, -1 on failure (for example if the output string was too short). </blockquote>
Converts an
npy_datetimestruct to an (almost) ISO 8601 NULL-terminated string. If the string fits in the space exactly, it leaves out the NULL terminator and returns success.
The differences from ISO 8601 are the 'NaT' string, and the number of year digits is >= 4 instead of strictly 4.
If 'local' is non-zero, it produces a string in local time with a +-#### timezone offset. If 'local' is zero and 'utc' is non-zero, produce a string ending with 'Z' to denote UTC. By default, no time zone information is attached.
'base' restricts the output to that unit. Set 'base' to -1 to auto-detect a base after which all the values are zero. <blockquote>
'tzoffset' is used if 'local' is enabled, and 'tzoffset' is set to a value other than -1. This is a manual override for the local time zone to use, as an offset in minutes.
'casting' controls whether data loss is allowed by truncating the data to a coarser unit. This interacts with 'local', slightly, in order to form a date unit string as a local time, the casting must be unsafe.
Returns 0 on success, -1 on failure (for example if the output string was too short). </blockquote>
Handle NaT, and treat a datetime with generic units as NaT
Only do local time within a reasonable year range. The years earlier than 1970 are not made local, because the Windows API raises an error when they are attempted (see the comments above the
get_localtime() function). For consistency, this restriction is applied to all platforms.
Note that this only affects how the datetime becomes a string. The result is still completely unambiguous, it only means that datetimes outside this range will not include a time zone when they are printed.
Automatically detect a good unit
If there's a timezone, use at least minutes precision, and never split up hours and minutes by default
Don't split up dates by default
Print weeks with the same precision as days.
- TODO: Could print weeks with YYYY-Www format if the week
- epoch is a Monday.
Use the C API to convert from UTC to local time
Set dts to point to our local time instead of the UTC time
Use the manually provided tzoffset
Set and apply the required timezone offset
Now the datetimestruct data is in the final form for the string representation, so ensure that the data is being cast according to the casting rule.
Producing a date as a local time is always 'unsafe'
Only 'unsafe' and 'same_kind' allow data loss
YEAR
Can't use PyOS_snprintf, because it always produces a '0' character at the end, and NumPy string types are permitted to have data all the way to the end of the buffer.
If it ran out of space or there isn't space for the NULL terminator
Stop if the unit is years
MONTH
Stop if the unit is months
DAY
Stop if the unit is days
HOUR
Stop if the unit is hours
MINUTE
Stop if the unit is minutes
SECOND
Stop if the unit is seconds
MILLISECOND
Stop if the unit is milliseconds
MICROSECOND
Stop if the unit is microseconds
NANOSECOND
Stop if the unit is nanoseconds
PICOSECOND
Stop if the unit is picoseconds
FEMTOSECOND
Stop if the unit is femtoseconds
ATTOSECOND
Add the +/- sign
Add the timezone offset
UTC "Zulu" time
Add a NULL terminator, and return