realworldocaml / examples

All the examples in Real World OCaml
The Unlicense
376 stars 81 forks source link

pass Core.Zone.local to Time.to_sec_string in log_entry #33

Open stu-art opened 9 years ago

stu-art commented 9 years ago

I received

Error: This expression has type zone:Core.Zone.t -> bytes                                        
       but an expression was expected of type bytes  

When entering the log_entry definition into utop. After some discussion in the #ocaml freenode room, this fixes the issue.

khanjehanzeb commented 9 years ago

Can anyone explain the reason why we have to pass Core.zone.local ?

agarwal commented 9 years ago

Can anyone explain the reason why we have to pass Core.zone.local ?

The resulting string will differ depending on the timezone, so what timezone should be assumed if you didn't have to pass this argument. You can't just assume local timezone because maybe you're generating a webpage and want to show the string in the user's timezone, rather than that of the server.

khanjehanzeb commented 9 years ago

so in the book there was a typo in the example ?

agarwal commented 9 years ago

I see what you mean. The API of Core has changed since the book was published. I just checked the older version of to_sec_string, and indeed it doesn't take a timezone argument. That's not very flexible, so I guess they improved the function since then.

OldPanda commented 7 years ago

Here's a SO answer explaining this https://stackoverflow.com/a/34224843/2191173

sharno commented 6 years ago

The API of Core has changed again: https://ocaml.janestreet.com/ocaml-core/v0.9/doc/core/Core__/Core_time_float/Zone/index.html

val local : t Core__.Import.Lazy.t

so passing local is not a solution for version 0.9 of Core I think it's better just to use to_string instead

teohhanhui commented 6 years ago

Or use:

Time.to_sec_string ~zone:Time.Zone.utc time