tryParseWeek

tryParseWeek, pure function

def pure tryParseWeek(source: text, format: text): (boolean, week)
// scalar format version
def pure tryParseWeek(source: text; format: text): (boolean, week)

The first argument is the value to be parsed. The second argument is the time format. The returned Boolean flag is true if the value has been parsed. The returned number value is non-default only if the parsing succeeded.

Example:

table T = with
  [| as Id, as Raw, as Format    |]
  [| 1, "202103",   "vvvvww"     |]
  [| 2, "2021-S03", "vvvv-'S'ww" |]
  [| 3, "2021S-03", "vvvv'S'-ww" |]
  [| 4, "2021S03",  "vvvv'S'ww"  |]

T.Ok, T.Parsed = tryParseWeek(T.Raw, T.Format) 

show table "Results" a1e4 with
  T.Id
  T.Raw
  T.Ok
  T.Parsed // 2021-W03

The “scalar format” version can be used when your format is fixed across all your values:

table T = with
  [| as Id, as Raw |]
  [| 1, "202103"   |]
  [| 2, "2021-S03" |]
  [| 3, "2021S-03" |]
  [| 4, "2021S03"  |]

// notice the usage of the ';' separator
T.Ok, T.Parsed = tryParseWeek(T.Raw; "vvvv'S'-ww") 

show table "Results" a1e4 with
  T.Id
  T.Raw
  T.Ok
  T.Parsed // 2021-W03

format specification

Beware, the standard Gregorian calendar and teh ISO-8601 calendar are different.

See also

User Contributed Notes
0 notes + add a note