Dates can be compared either with getTime or if in string format, we can compare "11/2/2014 < "11/3/2014".
remove String 'now' argument.
remove momentjs
Remove precision argument. If you need to compare based on precision, you can use the Intl.DateTimeFormat APIs to hone in on the comparison - { year: 'numeric' }. Even { dateStyle: 'full' } works!
Added locale option. Defaults to en-us when creating date times. This is probably less useful for the actual on/before/after but it can help in formatting your error message.
Note, I did my best with the short amount of time I looked at this + without an actual use case to test. Please let me know if there is something I missed!
close #69
Considerations
Dates can be compared either with
getTime
or if in string format, we can compare "11/2/2014 < "11/3/2014".precision
argument. If you need to compare based on precision, you can use the Intl.DateTimeFormat APIs to hone in on the comparison -{ year: 'numeric' }
. Even{ dateStyle: 'full' }
works!en-us
when creating date times. This is probably less useful for the actual on/before/after but it can help in formatting your error message.Some other options
In any case this will require a change in the
format
argument.e.g. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format