Skip to content

Commit

Permalink
Merge pull request #64 from daypack-dev/dev
Browse files Browse the repository at this point in the history
Timedesc: moved from mparser to angstrom, moved sexp code into timedesc-sexp
  • Loading branch information
darrenldl authored Jul 26, 2022
2 parents d81ba82 + 5818b5d commit dc73836
Show file tree
Hide file tree
Showing 39 changed files with 928 additions and 658 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

- Previously leads to incorrect result space computation, and may lead to time slots missing despite meeting criteria

## Timedesc 0.9.0

- Moved sexp code into `timedesc-sexp` to further reduce core dependencies

- Replaced use of mparser with angstrom

## Timedesc 0.8.0

- Significantly reduced number of dependencies, and moved JS, JSON code into separate packages
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SRCFILES = timedesc/*.ml timedesc/*.mli \
gen/*.ml \
timedesc-tzdb/*/*.ml timedesc-tzdb/*.mli \
timedesc-tzlocal/*/*.ml timedesc-tzlocal/*.mli \
timedesc-json/*.ml timedesc-json/*.mli \
timedesc-sexp/*.ml timedesc-sexp/*.mli \
export-js-tzdb-full/*.ml

OPAMFILES = *.opam
Expand Down
3 changes: 2 additions & 1 deletion debug/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

(rule
(targets of_sexp_utils.ml)
(deps ../timedesc/of_sexp_utils.ml)
(deps ../timedesc-sexp/of_sexp_utils.ml)
(action (copy %{deps} %{targets}))
)

Expand Down Expand Up @@ -154,6 +154,7 @@
diet
crowbar
timedesc
timedesc-sexp
timedesc-tzdb.full
timedesc-tzlocal.unix
)
Expand Down
17 changes: 14 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ Features:
(timedesc-tzdb (= :version))
(timedesc-tzlocal (= :version))
seq
(mparser (>= "1.3"))
(angstrom (>= "0.15.0"))
ptime
sexplib
(result (>= "1.5"))
(crowbar :with-test)
(alcotest :with-test)
Expand Down Expand Up @@ -91,6 +89,18 @@ Features:
)
)

(package
(name timedesc-sexp)
(synopsis "Timedesc Sexp backend")
(description "")
(depends
(ocaml (>= "4.08.1"))
dune
(timedesc (= :version))
(sexplib (>= "v0.14.0"))
)
)

(package
(name timere)
(synopsis "OCaml date time reasoning library")
Expand All @@ -116,7 +126,8 @@ Features:
(oseq (>= "0.3"))
(containers (>= "3.6"))
fmt
(timedesc (>= "0.8.0"))
(timedesc (>= "0.9.0"))
(timedesc-sexp (>= "0.9.0"))
(diet (>= "0.4"))
(crowbar :with-test)
(alcotest :with-test)
Expand Down
3 changes: 2 additions & 1 deletion fuzz/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

(rule
(targets of_sexp_utils.ml)
(deps ../timedesc/of_sexp_utils.ml)
(deps ../timedesc-sexp/of_sexp_utils.ml)
(action (copy %{deps} %{targets}))
)

Expand Down Expand Up @@ -158,6 +158,7 @@
fileutils
diet
timedesc
timedesc-sexp
timedesc-tzdb.full
timedesc-tzlocal.unix
)
Expand Down
3 changes: 2 additions & 1 deletion gen/dune
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
)
(libraries oseq
re
mparser
angstrom
containers
fileutils
ptime
timedesc
timedesc-tzdb.none
timedesc-tzlocal.none
timedesc-json
timedesc-sexp
yojson
bigarray
)
Expand Down
80 changes: 39 additions & 41 deletions gen/gen_time_zone_data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,77 +90,75 @@ let human_int_of_month s =
| _ -> failwith "Unexpected case"

module Parser = struct
open MParser
open Angstrom
open Parser_components

let tz_p =
attempt alpha_string
|>> (fun s -> String s)
<|> attempt
(char '+'
>>$ Plus
<|> (char '-' >>$ Minus)
>>= fun sign ->
digit
>>= fun h1 ->
digit
>>= fun h2 ->
let hour = int_of_string (Printf.sprintf "%c%c" h1 h2) in
digit
>>= (fun m1 ->
digit
|>> fun m2 ->
let minute = int_of_string (Printf.sprintf "%c%c" m1 m2) in
Offset (sign, (hour * 60) + minute))
<|> return (Offset (sign, hour * 60)))
alpha_string
>>| (fun s -> String s)
<|>
((char '+' *> return Plus)
<|> (char '-' *> return Minus)
>>= fun sign ->
digit
>>= fun h1 ->
digit
>>= fun h2 ->
let hour = int_of_string (Printf.sprintf "%c%c" h1 h2) in
(digit
>>= (fun m1 ->
digit
>>| fun m2 ->
let minute = int_of_string (Printf.sprintf "%c%c" m1 m2) in
Offset (sign, (hour * 60) + minute)))
<|> return (Offset (sign, hour * 60)))

let date_time_p =
non_space_string
>> spaces1
>> alpha_string
*> spaces1
*> alpha_string
>>= fun month ->
let month = human_int_of_month month in
spaces1
>> nat_zero
*> nat_zero
>>= fun day ->
spaces1
>> nat_zero
*> nat_zero
>>= fun hour ->
char ':'
>> nat_zero
*> nat_zero
>>= fun minute ->
char ':'
>> nat_zero
*> nat_zero
>>= fun second ->
spaces1
>> nat_zero
*> nat_zero
>>= fun year ->
spaces1 >> tz_p |>> fun tz -> { year; month; day; hour; minute; second; tz }
spaces1 *> tz_p >>| fun tz -> { year; month; day; hour; minute; second; tz }

let zdump_line =
non_space_string
>> spaces1
>> date_time_p
*> spaces1
*> date_time_p
>>= fun date_time_utc ->
assert (date_time_utc.tz = String "UT");
spaces1
>> char '='
>> spaces1
>> date_time_p
*> char '='
*> spaces1
*> date_time_p
>>= fun date_time_local ->
spaces1
>> string "isdst="
>> (char '0' >>$ false <|> (char '1' >>$ true))
*> string "isdst="
*> ((char '0' *> return false) <|> (char '1' *> return true))
>>= fun is_dst ->
spaces1
>> string "gmtoff="
>> (nat_zero <|> (char '-' >> nat_zero |>> fun x -> -x))
|>> fun offset -> { date_time_utc; date_time_local; is_dst; offset }
*> string "gmtoff="
*> (nat_zero <|> (char '-' *> nat_zero >>| fun x -> -x))
>>| fun offset -> { date_time_utc; date_time_local; is_dst; offset }
end

let parse_zdump_line (s : string) : (zdump_line, string) result =
MParser.parse_string Parser.zdump_line s ()
|> Parser_components.result_of_mparser_result
Angstrom.(parse_string ~consume:Prefix Parser.zdump_line s)

let transitions_of_zdump_lines (l : zdump_line list) : transition list =
let rec aux acc line_num l =
Expand Down Expand Up @@ -437,7 +435,7 @@ let () =
Printf.printf "Generating sexp serialization of tzdb: %s\n" sexp_output_file_name;
CCIO.with_out ~flags:output_flags sexp_output_file_name (fun oc ->
Format.fprintf (CCFormat.of_chan oc) "%a@." Sexp.pp
(Timedesc.Time_zone.Db.Sexp.to_sexp db));
(Timedesc_sexp.Time_zone.Db.to_sexp db));

Printf.printf "Generating compressed serialization of tzdb: %s\n" compressed_output_file_name;
CCIO.with_out ~flags:output_flags compressed_output_file_name (fun oc ->
Expand Down
1 change: 1 addition & 0 deletions publish-timedesc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ packages=(
"timedesc-tzlocal"
"timedesc-tzlocal-js"
"timedesc-json"
"timedesc-sexp"
)

for package in ${packages[@]}; do
Expand Down
33 changes: 33 additions & 0 deletions timedesc-sexp.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Timedesc Sexp backend"
description: ""
maintainer: ["Darren Ldl <[email protected]>"]
authors: ["Daypack developers"]
license: "MIT"
homepage: "https://github.com/daypack-dev/timere"
bug-reports: "https://github.com/daypack-dev/timere/issues"
depends: [
"ocaml" {>= "4.08.1"}
"dune" {>= "2.9"}
"timedesc" {= version}
"sexplib" {>= "v0.14.0"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"--promote-install-files=false"
"@install"

"@doc" {with-doc}
]
["dune" "install" "-p" name "--create-install-files" name]
]
dev-repo: "git+https://github.com/daypack-dev/timere.git"
17 changes: 17 additions & 0 deletions timedesc-sexp/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(rule
(targets date_time_utils.ml)
(deps ../timedesc/date_time_utils.ml)
(action (copy %{deps} %{targets}))
)

(library
(flags (-w "+a-4-9-29-37-40-42-44-48-50-70@8"))
(name timedesc_sexp)
(public_name timedesc-sexp)
(instrumentation (backend bisect_ppx))
(libraries
timedesc
sexplib
)
)

Loading

0 comments on commit dc73836

Please sign in to comment.