Skip to content

Zone and Era for package developers #8

@AdrianRibao

Description

@AdrianRibao

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions