⏱️ An anwsome and tiny util package for timestamp without dependencies
npm install timestamp-utils⏱️ An anwsome and tiny util package for timestamp without dependencies
---------------------------------------




- timestamp-utils
- Navigation 🗺️ :
- Why 🤔
- How to use ✍️
- API 📖
- [decompose(timestamp, [timezone='UTC'])](#decomposetimestamp-timezoneutc)
- getYear(timestamp)
- getMonth(timestamp)
- getWeekDay(timestamp)
- getDay(timestamp)
- getHours(timestamp)
- getMinutes(timestamp)
- getSeconds(timestamp)
- getMilliseconds(timestamp)
- addYears(timestamp, years)
- addMonths(timestamp, months)
- addDays(timestamp, days)
- addHours(timestamp, hours)
- addMinutes(timestamp, minutes)
- addSeconds(timestamp, seconds)
- addMilliseconds(timestamp, milliseconds)
- add(timestamp, values)
- setYear(timestamp, year)
- setMonth(timestamp, month)
- setWeekDay(timestamp, weekDay)
- setDay(timestamp, day)
- setHours(timestamp, hours)
- setMinutes(timestamp, minutes)
- setSeconds(timestamp, seconds)
- setMilliseconds(timestamp, millisecondes)
- set(timestamp, values)
- setTimezone(timezone)
- Changelog 📋
- v2.2.0
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- Development 💻
- License 🖋
Because when you manipulate date with javascript Date class it automatically apply the current timezone.
Using timestamp is a good way to avoid timezones's influences.
But using timestamp for huge maninupulations can be very hard (ex: go to next months).
That why i created timestamp-utils, it's a powerful util package to easly manipulate timestamp.
Install timestamp-utils via npm :
```
npm install --save timestamp-utils
Or via yarn :
``
yarn add timestamp-utils
Use it :
`javascript
import t from 'timestamp-utils'
const now = new Date().getTime()
const timestamp = t.addDays(now, 3)
`
Decompose timestamp to the following array pattern :[year, month, day, hours, minutes, seconds, milliseconds]
---------------------------------------
Return the timestamp's year.
---------------------------------------
Return the timestamp's month (eg: "01" for "january").
---------------------------------------
Return the timestamp's week day (eg: 0 for "monday").
---------------------------------------
Return the timestamp's day (eg: "01" for "monday").
---------------------------------------
Return the timestamp's hours.
---------------------------------------
Return the timestamp's minutes.
---------------------------------------
Return the timestamp's seconds.
---------------------------------------
Return the timestamp's milliseconds.
---------------------------------------
Add the given years to the given timestamp.years can be negative to subtract years.
---------------------------------------
Add the given months to the given timestamp.months can be negative to subtract months.
> ⚠️ Note : addMonths doesn't add same amont of day.addMonths
> add days depends on the given day, the result is always the nearest month's day that the given month's day :
>
> * 09 October + 1 month => 09 November (+31 days)
> * 31 August + 1 month => 30 September (+30 days)
> * 31 January 2018 + 1 month => 28 February (+28 days)
---------------------------------------
Add the given days to the given timestamp.days can be negative to subtract days.
---------------------------------------
Add the given hours to the given timestamp.hours can be negative to subtract hours.
---------------------------------------
Add the given minutes to the given timestamp.minutes can be negative to subtract minutes.
---------------------------------------
Add the given seconds to the given timestamp.seconds can be negative to subtract seconds.
---------------------------------------
Add the given milliseconds to the given timestamp.milliseconds can be negative to subtract milliseconds.
---------------------------------------
add is a combo of all previous "add" methods.values is an object that follow this pattern :{ years, months, days, hours, minutes, seconds, milliseconds }values
All values are int and represent the key value to add.
Example : { years: 3, days: -1, seconds: 20 } will add 3 years, subtract 1 days and add 20 seconds to the given timestamp.
> ⚠️ Note : add calls addMilliseconds, addSeconds, addMinutes, addHours, addDays, addMonths and addYears in this order.add(t, { days: -1, months: -1 })
> That mean, according to addMonths's note, and addDays(addMonths(t, -1), -1) are not always equals.add(30 March 2018, { days: -1, months: -1 })
> Example : => 28 February 2018, addDays(addMonths(30 March 2018, -1), -1) => 27 February 2018
---------------------------------------
Set the given year to the given timestamp.
---------------------------------------
Set the given month to the given timestamp.
---------------------------------------
Set the given weekDay to the given timestamp.
> ⚠️ Note : weekDay must be an integer between 0 and 6 (0 for Monday, 6 for Sunday)
---------------------------------------
Set the given day to the given timestamp.
---------------------------------------
Set the given hours to the given timestamp.
---------------------------------------
Set the given minutes to the given timestamp.
---------------------------------------
Set the given seconds to the given timestamp.
---------------------------------------
Set the given millisecondes to the given timestamp.
---------------------------------------
set is a combo of all previous "set" methods.values is an object that follow this pattern :{ year, month, day, hours, minutes, seconds, milliseconds }values
All values are int and represent the key value to add.
Example : { year: 1992, days: 9, seconds: 14 } will set year to 1992, day to 9 and seconds to 14 to the given timestamp.
---------------------------------------
Set the global timezone that timestamp-utils should use.
---------------------------------------
value for set method #125 #181.
* Fix timezoneOffset util date parsing #183.$3
* Adding
set methods :
- setYear(timestamp, year)
- setMonth(timestamp, month)
- setWeekDay(timestamp, weekDay)
- setDay(timestamp, day)
- setHours(timestamp, hours)
- setMinutes(timestamp, minutes)
- setSeconds(timestamp, seconds)
- setMilliseconds(timestamp, millisecondes)
- set(timestamp, values)$3
* Fix getWeekDay usage of timezone.
$3
* Fix decompose slow execution speed.
$3
* decompose is no longer accessible by using deconstructing import. Now decompose is accessible by doing :
`javascript
import t from 'timestamp-utils'
const results = t.decompose(now)
`* decompose now support timezone :
`javascript
import t from 'timestamp-utils'
const results = t.decompose(now, 'Europe/Paris')
`* New method
setTimezone :`javascript
import t from 'timestamp-utils'
t.setTimezone('Europe/Paris')
`---------------------------------------
Development 💻
`
// Clone the project
git clone git@github.com:lelivrescolaire/react-light-calendar.git// ⬇️ Install node modules
npm install
// 🚀 Start the project
npm run watch
// ✅ Run tests
npm run test
// 🏗️ Build the project
npm run build
// 👀 Keep an eye on the bundle size
npm run size
``