1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
open Resume_t
let ascii_printable c =
let n = Char.code c in
n >= 32 && n <= 127
(*
Check that string is not empty and contains only ASCII printable
characters (for the sake of the example; we use UTF-8 these days)
*)
let validate_some_text s =
s <> "" &&
try
String.iter (fun c -> if not (ascii_printable c) then raise Exit) s;
true
with Exit ->
false
(*
Check that the combination of year, month and day exists in the
Gregorian calendar.
*)
let validate_date x =
let y = x.year in
let m = x.month in
let d = x.day in
m >= 1 && m <= 12 && d >= 1 &&
(let dmax =
match m with
2 ->
if y mod 4 = 0 && not (y mod 100 = 0) || y mod 400 = 0 then 29
else 28
| 1 | 3 | 5 | 7 | 8 | 10 | 12 -> 31
| _ -> 30
in
d <= dmax)
(* Compare dates chronologically *)
let compare_date a b =
let c = compare a.year b.year in
if c <> 0 then c
else
let c = compare a.month b.month in
if c <> 0 then c
else compare a.day b.day
(* Check that the end_date, when defined, is not earlier than the start_date *)
let validate_job x =
match x.end_date with
None -> true
| Some end_date ->
compare_date x.start_date end_date <= 0
|