Skip to content

Commit

Permalink
Use regex to drop trailing .000 on datetime fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcgilchrist committed Mar 20, 2021
1 parent 6e6b289 commit 8edea6b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/aws.ml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,15 @@ module Time = struct

let now_utc () = C.(now () |> to_gmt)

let parse s = P.from_fstring "%Y-%m-%dT%T" (String.sub s 0 (String.length s - 5))
(* (tmcgilchrist) This function is expecting datetimes like
- "2021-03-17T21:43:32.000Z" from EC2 or
- "2021-03-18T09:38:33Z" from STS
We regex off the trailing ".000" and parse them. If there are other
datetime formats in xml / json there will be trouble and the parser
will fail with xml node not present or json attribute not present.
*)
let parse s = P.from_fstring "%Y-%m-%dT%TZ"
(Str.replace_first (Str.regexp "\\.\\([0-9][0-9][0-9]\\)") "" s)

let format t = P.sprint "%Y-%m-%dT%T.000Z" t
end
Expand Down

0 comments on commit 8edea6b

Please sign in to comment.