You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 3 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Date Arthmetic
  2. =================
  3. A simple object containing some date math utils in the spirit of Moment.js. Unlike Moment this module, returns real date objects, so it isn't chainable.
  4. import * as dateMath from 'date-arithmetic'
  5. var date = dateMath.month(new Date)
  6. ## API
  7. all api methods return a _new_ date. Date objects are never mutated.
  8. ### Accessors
  9. get and set date part values.
  10. - `dateMath.milliseconds(date, [value])`
  11. - `dateMath.seconds(date, [value])`
  12. - `dateMath.minutes(date, [value])`
  13. - `dateMath.hours(date, [value])`
  14. - `dateMath.date(date, [value])`
  15. - `dateMath.day(date, [value])`
  16. - `dateMath.weekday(date, [value], [firstOfWeek = 0])`
  17. - `dateMath.month(date, [value])`
  18. - `dateMath.year(date, [value])`
  19. - `dateMath.decade(date, [value])`
  20. - `dateMath.century(date, [value])`
  21. ### `startOf(data, unit, [firstOfWeek = 0])`
  22. return a new date with the relevent date parts zero'd out. You only need to provide a `firstOfWeek` when the unit is `'week'`
  23. dateMath.startOf(new Date, 'day') // -> no time components
  24. Valid unit values are; `"seconds", "minutes", "hours", "day", "week", "month", "year", "decade", "century" `
  25. ### `endOf(data, unit)`
  26. the opposite of `startOf`
  27. dateMath.endOf(new Date, 'day') // -> one millisecond before tomorrow
  28. Valid unit values are; `"milliseconds", "seconds", "minutes", "hours", "day", "weekday", "month", "year", "decade", "century"`.
  29. ### Math Functions
  30. Arithmetic functions
  31. - `dateMath.add(date, value, unit)`
  32. - `dateMath.subtract(date, value, unit)`
  33. - `dateMath.eq(dateA, dateB, [unit])`
  34. - `dateMath.neq(dateA, dateB, [unit])`
  35. - `dateMath.gte(dateA, dateB, [unit])`
  36. - `dateMath.gt(dateA, dateB, [unit])`
  37. - `dateMath.lte(dateA, dateB, [unit])`
  38. - `dateMath.lt(dateA, dateB, [unit])`
  39. - `dateMath.inRange(day, min, max, unit)`
  40. - `dateMath.min(dateA, dateB, dateN)`
  41. - `dateMath.max(dateA, dateB, dateN)`
  42. - `dateMath.diff(dateA, dateB, unit, asFloat)`
  43. Valid unit values are; `"seconds", "minutes", "hours", "day", "week", "month", "year", "decade", "century" `