strftime, strptime
platform independent implementation.
Consts
NotImplDirectives = {'y', '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 <-:
- 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
- Z: Time zone name (no characters if no time zone exists). Deprecated. However, this is supported in Lib/datetime
Following are strftime only currently:
- j: Day of the year as a decimal number [001,366]. <- DateTime.yearday + 1
- u: Weekday [0(Monday), 6]. <- DateTime.weekday.int
- w: Weekday [0(Sunday),6]. <- (DateTime.weekday.int + 1) mod 7
- 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.
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