Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zone and Era for package developers #8

Open
AdrianRibao opened this issue Oct 13, 2018 · 3 comments · May be fixed by #9
Open

Zone and Era for package developers #8

AdrianRibao opened this issue Oct 13, 2018 · 3 comments · May be fixed by #9

Comments

@AdrianRibao
Copy link

I'm writing a library based on this new time api: https://github.com/AdrianRibao/elm-derberos-date

So far it's ok and all tests pass (101 at the moment) but I still haven't introduced the zones in the functions. To do that, I need to adjust the posix time. I was going to copy the code from this library:

-- HELPERS FROM elm/time
-- Some of these functions are useful for this library, but are not exposed in elm/time
-- so they have been copied here.
-- Original code: https://github.com/elm/time/blob/1.0.0/src/Time.elm
-- Copyright (c) 2018-present, Evan Czaplicki

toAdjustedMinutes : Zone -> Posix -> Int
toAdjustedMinutes (Zone defaultOffset eras) time =
    toAdjustedMinutesHelp defaultOffset (flooredDiv (posixToMillis time) 60000) eras


toAdjustedMinutesHelp : Int -> Int -> List Era -> Int
toAdjustedMinutesHelp defaultOffset posixMinutes eras =
    case eras of
        [] ->
            posixMinutes + defaultOffset

        era :: olderEras ->
            if era.start < posixMinutes then
                posixMinutes + era.offset
            else
                toAdjustedMinutesHelp defaultOffset posixMinutes olderEras


flooredDiv : Int -> Float -> Int
flooredDiv numerator denominator =
    floor (toFloat numerator / denominator)

but I have two problems:

  • Era is not exposed in the module
  • I can't pattern match toAdjustedMinutes (Zone defaultOffset eras) time = because I don't have a Zone constructor

Is it possible to expose Era and a Zone so I don't have to copy them in the library?

@joshuaclayton
Copy link

To piggy-back on this, I'm looking to write an encoder for the Zone type, but without access to its data constructor or internals (offset and list of Eras), it seems like it's infeasible. customZone allows for decoding, though, so that portion seems to be covered.

@AdrianRibao
Copy link
Author

I'm totally blocked on this. I tried to create an internal zone representation that is the same to the one on this library

type Zone
    = Zone Int (List Era)

but I cannot create a function like this:

convertToInternalZone : Time.Zone -> Zone

that takes a Zone from Time and convert it to the internal representation.

Am I totally blocked without exposing the Zone constructor and Era or maybe there is something I can do that I haven't figured out?

@AdrianRibao AdrianRibao linked a pull request Oct 23, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants