strftime, strptime
platform independent implementation.
Consts
docTable = (module: ".. warning:: A few of the format directives for `strftime`/`strptime` are not supported,\r\n and using them causes `AssertDefect`. They are listed in\r\n `nstrfptime.NotImplDirectives<time_impl/nstrpftime.html#NotImplDirectives>`_", api: (data: [ (0, "", ""), (0, "", ""), (0, "", ""), (505641947, "strptime", ".. warning:: In current implementation,\r\n whitespace in format string means itself AS-IS, unlike C or Python,\r\n where any whitespace means a serial of any whitespaces. If really\r\n wanting the behavior of C\'s, consider using `std/strscan`.\r\n\r\n.. warning:: Current `strptime`\r\n is just locale-unaware, when it comes to \r\n \"the locale\'s format\", like `\"%x\"`, it always uses the format of\r\n `\"C\" locale`, no matter what the locale is. a.k.a. Changing\r\n locale via C\'s api in `<locale.h>` doesn\'t affect this function.\r\n"), (0, "", ""), (0, "", ""), (0, "", ""), (0, "", "")], counter: 1))
- used to transport doc string to outer module. Source Edit
NotImplDirectives = {'j', 'w', 'y', 'U', 'Z'}
-
Here are their concrete meanings in Python, as well as some notes about why they cannot be directly mapped to Nim's DateTime.format/parse.
The direct alternative value when formatting in Nim, if any, is introduced by <-:
- j: Day of the year as a decimal number [001,366]. <- DateTime.yearday + 1
- w: Weekday [0(Sunday),6]. <- (DateTime.weekday.int + 1) mod 7
- y: Year without century as a decimal number [00,99]. <- DateTime.format"yy" When parsing, C/Python's %y use 20th or 21th centry depending on the value of %y Nim's yy use the current century
- U: Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0. Nim's V or VV is of range [1,53] (times.IsoWeekRange, get via DateTime.getIsoWeekAndYear) and use Monday as the first day of a week. (Nim's is iso-week, Python's is not)
- Z: Time zone name (no characters if no time zone exists). Deprecated. Impossible to implement without interacting with C lib. Any way, it's deprecated.
Procs
proc strptime(dt: var DateTime; s: string; format_with_sp_asis: string) {. ...raises: [ValueError, TimeParseError, TimeFormatParseError], tags: [TimeEffect], forbids: [].}
-
Warning: In current implementation, whitespace in format string means itself AS-IS, unlike C or Python, where any whitespace means a serial of any whitespaces. If really wanting the behavior of C's, consider using std/strscan.Warning: Current strptime is just locale-unaware, when it comes to "the locale's format", like "%x", it always uses the format of "C" locale, no matter what the locale is. a.k.a. Changing locale via C's api in <locale.h> doesn't affect this function.Source Edit