Git Product home page Git Product logo

date's People

Contributors

2mol avatar justinmimbs avatar kofigumbs avatar kutyel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

date's Issues

Function request: isLeapYear (with possible solution)

Hi, first: great package - thank you very much for it.
I have this function for determining if a year is a leap year, may you want to integrate it? Can be very useful, for example for date pickers:

isLeapYear : Int -> Bool
isLeapYear year =
    case modBy 4 year of
        0 ->
            if String.endsWith "00" (String.fromInt year) then
                case modBy 400 year of
                    0 ->
                        True

                    _ ->
                        False

            else
                True

        _ ->
            False

and here the tests for this function:

suite : Test
suite =
    describe "A leap year is divisible by 4 when it's not the last year of a century (e.g. 1800) that is not divisible by 400 (e.g. 2000)"
        [ test "2019 is not a leap year" <|
            \_ -> False |> Expect.equal (Date.isLeapYear 2019)
        , test "2020 is a leap year" <|
            \_ -> True |> Expect.equal (Date.isLeapYear 2020)
        , test "2000 is a leap year" <|
            \_ -> True |> Expect.equal (Date.isLeapYear 2000)
        , test "2100 is not a leap year" <|
            \_ -> False |> Expect.equal (Date.isLeapYear 2100)
        ]

BR pfiadDi

Consider adding a toPosix function

Hi!

Thanks for the Date type, it definitely makes my life easier!

However, when dealing with Firestore stuff with elm I had the need to convert dates to Posix, would you consider adding this function to the library?

toPosix : Date -> Posix

Thanks and keep up the good work! ๐Ÿ’ช๐Ÿป

Expose default language

Hello, and thanks for this great lib!

Would it be possible to expose language_en in next version? We'd like to reuse parts of it in various places of our application, would be great to avoid duplicating code.

Have a nice day.

Human-readable value display in elm-test diffs

I am not sure, how this can be done. A quick search didn't bring up any hints...

My issue is that when testing with dates and they don't match, the diff from elm-test looks like

    RD 736956
    โ•ท
    โ”‚ Expect.equal
    โ•ต
    RD 736969

It would be much more helpful, if it would display in ISO format instead:

    Date 2018-10-06
    โ•ท
    โ”‚ Expect.equal
    โ•ต
    Date 2018-11-06

Again, I'm not sure how easily this is possible. If you can point me to resources on how this might be done, I could take a crack at creating a PR.

Change signature of `now`

Hey there,

Currently the type signature of now is Task Never Date. This can cause some problems when chaining this task to other things. For example:

myOtherTask : Task CustomError MyResult

Date.now
|> Task.andThen myOtherTask

This will fail to compile, because myOtherTask's error type is CustomError and now's error type is Never.

In elm/time, this is solved by having the type of Time.now beTask x Posix. I was able to solve this in my use case by replace Date.now with Task.map2 Date.fromPosix Time.here Time.now, which is the exact definition of now in this package.

I believe this could be fixed by just changing the signature of now to be:

today : Task x Date

This would be a breaking change, but would allow now to be used more flexible. Additionally, I don't believe it would break anyone's code when updating as x can be inferred to Never in any case. What are your thoughts?

Reuse types from elm/time

Both justinmimbs/date and elm/time expose Weekday and Month with identical semantics.

Seeing that elm/time is a core package would it be possible to change this packages interface to use elm/time types where available?

Maybe I am missing something obvious here...

min max for dates

Hi! I noticed there are not yet any min/max functions like for comparables in core of the type

min : Date -> Date -> Date

Are you interested in having those? I can dedicate some time and send you a PR

To unix timestamp

Hi Justin,

Sorry to have to ask you this but is there a way to convert a type Date back to unix timestamp.

Aron

How can I express my gratitude?

Justin,

The drop-in modules you're built have been remarkably helpful and beneficial to me in getting upgraded from 0.18 to 0.19.

Is there a way to get you a coffee โ˜•๏ธ or a beer ๐Ÿบ or a book ๐Ÿ“š as a means of expressing my gratitude for your effort?

Thanks ๐Ÿ™‡

Andrew

Confusing error message when parsing date

Date.fromIsoString "1999-" returns Expected a date in ISO 8601 format; Expected a date in ISO 8601 format; Expected a date in ISO 8601 format instead of just Expected a date in ISO 8601 format.

Unix timestamp

Is there any possibility right now that i can convert a unix timestamp into a Date type? If not do you plan on adding that functionality?

Language support for `format`

In its current iteration the format function formats to English, and that's it. A sensible default, but it may be worth considering a FormatConfig type (record alias) that can be easily modified for the format functions needed (such as ordinalSuffix and monthToName).

I don't desperately need this right now, but figured it would be worth knowing your position on the topic and considering pros and cons with this (and other) approach(es), if this is a problem you want to solve in this package at some point.

Feel free to close the issue when you feel it has been sufficiently explored or if it is not something you want to do.

Invalid result when subtracting months

Hey I have found an issue when using https://package.elm-lang.org/packages/justinmimbs/date/latest/Date#add`, here is a simple reproduction script:

        may2021 =
            Result.toMaybe (Date.fromIsoString "2021-05-01")

        dec2020 =
            Maybe.map (Date.add Date.Months -5) may2021

        jan2021 =
            Maybe.map (Date.add Date.Months -4) may2021

        feb2021 =
            Maybe.map (Date.add Date.Months -3) may2021

        _ =
            Debug.log "may2021" (Maybe.map (Date.format "dd-MM-YYYY") may2021)

        _ =
            Debug.log "dec2020" (Maybe.map (Date.format "dd-MM-YYYY") dec2020)

        _ =
            Debug.log "jan2021" (Maybe.map (Date.format "dd-MM-YYYY") jan2021)

        _ =
            Debug.log "feb2021" (Maybe.map (Date.format "dd-MM-YYYY") feb2021)

it will print out:

may2021: Just "01-05-2021"
dec2020: Just "01-12-2020"
jan2021: Just "01-01-2020"
feb2021: Just "01-02-2021"

Notice how jan2021 is "01-01-2020" instead of "01-01-2021".

I'll try to use a workaround of adding positive numbers instead of negatives, but it would be nice if I could keep my logic as is.

Expose fromCalendarParts

Is there a reason not to expose useful functions like fromCalendarParts that can fail with Result? They would be useful.

Error when trying to parse an actually ISO8601 valid date string

Using latest 3.1.1, trying to parse this ISO 8601 formatted date 2018-07-30T09:58:48.841Z, I'm getting an error saying it's invalid:

> import Date
> Date.fromIsoString "2018-07-30T09:58:48.841Z"
Err ("String is not in IS0 8601 date format")
    : Result String Date.Date

Minimum selectable date

It'd be nice to have a minimum selectable date.
I quite commonly need a datepicker that doesn't allow you to select a date in the past.

Forgive me if this is actually possible currently, but from reading the docs it seems like you can't do this.

cheers

fromIsoString should return why detailed reason why the date is invalid

In the example:

fromIsoString "2018-02-29"
    == Err "Invalid calendar date (2018, 2, 29)"

I would like to have more detailed messages. For example, I might expect it to mention that the day field is invalid and a valid range for the day field (01 to 28). I would expect the same for the month field (01 to 12).

Please add a CHANGELOG

Hi
Thanks for making this package, is very nice.

Could you please add a changelog to the repo? It is very useful for upgrading, specially when functions are removed or renamed.

Thanks

Closing gap to 0.18 elm-date-extra

If I understand it correctly this package is a mix between the old elm-core/date and justinmimbs/elm-date-extra.

Alas there is still some stuff from the elm-date-extra package missing.
I.e. isBetween or some way to order dates (in 0.18 I used Date.toTime)

Are you planning on closing that gap, or is the currently released API likely gonna stay?

Date formatting in 2019

Hello,

working with 3.2.1, I got a strange formatting for the end of last year :

  > import Date
  > Date.fromIsoString "2019-12-31" |> Result.map (Date.toIsoString)
  Ok "2019-12-31"
  >  Date.fromIsoString "2019-12-31" |> Result.map (Date.format "dd/MM/YYYY")
  Ok "31/12/2020"

I did not have time to investigate code further but I report in case you have an idea.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.