aboutsummaryrefslogtreecommitdiff
path: root/lib/fixture.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fixture.ml')
-rw-r--r--lib/fixture.ml17
1 files changed, 16 insertions, 1 deletions
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