From 20c5abba2f762e917503e3d613729f12607baf88 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Fri, 12 Jan 2024 08:01:25 -0600 Subject: Implement support for dates --- lib/fixture.ml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/fixture.ml') diff --git a/lib/fixture.ml b/lib/fixture.ml index d34b155..47ae453 100644 --- a/lib/fixture.ml +++ b/lib/fixture.ml @@ -107,6 +107,9 @@ type t = | Increment of string | Const of string * string | Email of string + | Past of string + | Future of string + | Now of string | List of string * string list (* (Name, foreign ids to pick from) *) @@ -121,6 +124,16 @@ let generate_fixture index fixture = | Const (_, value) -> String value | Email _ -> String (random_email str_index ()) | Int (_, min, max) -> Int (Random.int (max - min) + min) + | Past _ -> + let now = Unix.time () in + String (ISO8601.Permissive.string_of_datetimezone (Random.float now, 0.)) + | Future _ -> + let now = Unix.time () in + String + (ISO8601.Permissive.string_of_datetimezone (Random.float (Float.mul now 2.), 0.)) + | Now _ -> + let now = Unix.time () in + String (ISO8601.Permissive.string_of_datetimezone (now, 0.)) | List (_, values) -> String (random_value_in_list values ()) @@ -135,7 +148,6 @@ let%test "random_value_in_list" = (* TODO: Support "hashed" password *) -(* TODO: Support dates *) (* TODO: Support variables using @ *) let rec replicate element n = @@ -160,6 +172,9 @@ let id_of_fixture fixture = | Int (id, _, _) -> id | List (id, _) -> id | Email id -> id + | Past id -> id + | Future id -> id + | Now id -> id in String id -- cgit v1.2.3