spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.97k stars 185 forks source link

Unable to calculate days difference #353

Closed vresetnikov closed 1 year ago

vresetnikov commented 1 year ago

Hello,

It appears there is a missing type definition or perhaps a simple mismatch with what is written in the documentation:

The official spacetime documentation here on Github demonstrates that it is possible to calculate the difference between 2 dates in such a manner:

s.diff(s.endOf('year'), 'days')

However, attempting to follow the provided instructions makes Typescript raise the following issue:

image

The code runs fine nonetheless, leading me to believe that perhaps this function parameter type was omitted by accident:

export type TimeUnit =
  | 'millisecond'
  | 'second'
  | 'minute'
  | 'quarterHour'
  | 'hour'
  | 'day'
  | 'week'
  | 'month'
  | 'quarter'
  | 'season'
  | 'year'
  | 'decade'
  | 'century'
  | 'date'

Changing the keyword from 'days' to 'day' eliminates the Typescript error and works fine as well. This problem has been encountered in ver. 7.2.0

I would also like to take time to thank you for this library, everything else that performs date operations pales in comparison to this library and its intuitiveness and ease of use.

Thank you

spencermountain commented 1 year ago

thanks! I'll add it to the next release cheers

spencermountain commented 1 year ago

fixed in 7.3.0 thanks