Permalink
Browse files

[fix] stdlib/api/github: Dates are now Date.date instead of string

  • Loading branch information...
1 parent fdba049 commit 2aba0fa302b0daf1246deaafe99283d92657a333 Nicolas Glondu committed with François-Régis Sinot Jun 21, 2011
@@ -31,17 +31,15 @@
/* Types returned by API */
-type gdate = string
-
type GitHub.repository = {
name : string
owner : string
homepage : string /* Not always returned */
url : string
description : string
language : string
- created_at : gdate
- pushed_at : gdate
+ created_at : Date.date
+ pushed_at : Date.date
size : int
private : bool
fork : bool
@@ -34,7 +34,7 @@ import stdlib.apis.github
type GHParse.map = {
str : string -> string
- date : string -> string
+ date : string -> Date.date
int : string -> int
bool : string -> bool
float : string -> float
@@ -105,19 +105,36 @@ GHLib = {{
GHParse = {{
-/* WIP: Date parser
parse_date(str) =
- n = parser v=([0-9]+) -> Int.of_string(Text.to_string(v))
+ int_of_text(t) = Int.of_string(Text.to_string(t))
+ n = parser k=[0-9] -> k
+ nn = parser v=(n+) -> int_of_text(v)
+ shift(forward,h,m) =
+ h = int_of_text(h)
+ min = int_of_text(m)
+ d = { Duration.zero with ~forward ~h ~min }
+ |> Duration.of_human_readable
+ Date.advance(_, d)
tmz = parser
- |
+ | "Z" -> identity
+ | "-" h=(n n) m=(n n) -> shift(true, h, m)
+ | "-" h=(n n) ":" m=(n n) -> shift(true, h, m)
+ | "+" h=(n n) m=(n n) -> shift(false, h, m)
+ | "+" h=(n n) ":" m=(n n) -> shift(false, h, m)
+ | .* -> identity
p = parser
- | y=n "/" m=n "/" d=n " " h=n ":" m=n ":" s=n " " tmz=
-*/
+ | y=nn "/" m=nn "/" d=nn " " h=nn ":" min=nn ":" s=nn " " tmz=tmz ->
+ m = Date.Month.of_int(m-1)
+ tmz(Date.build({year=y month=m day=d h=h min=min s=s}))
+ | y=nn "-" m=nn "-" d=nn "T" h=nn ":" min=nn ":" s=nn tmz=tmz ->
+ m = Date.Month.of_int(m-1)
+ tmz(Date.build({year=y month=m day=d h=h min=min s=s}))
+ Parser.try_parse(p, str) ? Date.epoch
map_funs(srcmap) =
map = JsonOpa.record_fields(srcmap) ? Map.empty
str = API_libs_private.map_get_string(_, map)
- date = str
+ date(field) = str(field) |> parse_date
int = API_libs_private.map_get_int(_, map)
bool = API_libs_private.map_get_bool(_, map, false)
float = API_libs_private.map_get_float(_, map)
@@ -62,7 +62,7 @@ type GitHub.pull_req = {
user : GitHub.user_simple
comments : int
votes : int
- state : {open}/{closed:gdate}/{other:string} /* Todo: Date ? (closed_at) */
+ state : {open}/{closed:Date.date}/{other:string}
position : float
number : int
head : GitHub.commit
@@ -71,11 +71,11 @@ type GitHub.pull_req = {
diff_url : string
html_url : string
patch_url : string
- issue_created_at : gdate
- issue_updated_at : gdate
- created_at : gdate
- updated_at : gdate
- merged_at : gdate
+ issue_created_at : Date.date
+ issue_updated_at : Date.date
+ created_at : Date.date
+ updated_at : Date.date
+ merged_at : Date.date
// labels : list(string) ???
// mergeable : string ???
}
@@ -63,7 +63,7 @@ type GitHub.user = {
name : string
company : string
gravatar_id : string
- created_at : gdate
+ created_at : Date.date
location : string
blog : string
public_repo_count : int

0 comments on commit 2aba0fa

Please sign in to comment.