moment-loyall
v1.3.0
Published
Moment.js extended
Downloads
3,474
Readme
Moment Loyall
It's an extended version of
moment-timezone
package with extra functions.
Moment.js
It extends the moment-timezone, so we have all the built in functions and a few more.
How to use it
$ npm i -S moment-loyall
Then just import as a normal module
import moment from "moment-loyall";
moment();
Holidays - isHoliday
Moment Loyall has all Brazil National Holidays and São Paulo specific holidays for the stock marketing. The parameter Holiday Calendar
is required, see the avaiable list bellow:
- "sp": B3 and National Holidays
- "brasil": Only National Holidays
- "us": United States National Holidays
- "mexico": Mexico National Holidays
- "uk": United Kingdom National Holidays
- "argentina": Argentina National Holidays
- "france": France National Holidays
- "italy": Italy National Holidays
- "swiss": Switzerland National Holidays
- "spain": Spain National Holidays
const isHoliday = moment("2020-12-25").isHoliday("brasil");
// isHoliday = true
Holidays - getHolidays
Gets an array of holidays
const holidays = moment().getHolidays("sp");
// holidays = [ '2020-12-25', ...]
Business Day - isBusinessDay
Check if date is a business day
const holidays = moment("2020-04-14").isBusinessDay("brasil");
// true
Business Day - nextBusinessDay
Get date next business day
const holidays = moment("2020-04-14").nextBusinessDay("brasil");
// 2020-04-15
Business Day - prevBusinessDay
Get date previous business day
const holidays = moment("2020-04-14").nextBusinessDay("brasil");
// 2020-04-13
Business Day - businessAdd
Add period off business day form the date
const holidays = moment("2020-04-14").businessAdd(2, "days", "brasil");
// 2020-04-16
Business Day - businessSubtract
Subtract period off business day form the date
const holidays = moment("2020-04-10").businessSubtract(2, "days", "brasil");
// 2020-04-16
Business Day - businessDiff
Get the number off business day between two dates
const holidays = moment("2020-04-10").businessDiff(moment("2020-04-01"), "brasil");
// 8
/**
* To return an array of dates you need to pass a third argument
*/
const holidays = moment("2020-04-10").businessDiff(moment("2020-04-01"), "brasil", true);
// [ '2020-04-01',
// '2020-04-02',
// '2020-04-03',
// '2020-04-06',
// '2020-04-07',
// '2020-04-08',
// '2020-04-09',
// '2020-04-13' ]
Relative dates - moment.parseRelativeDate
Parse D-* notation (D0, D-1, D+1, etc)
// Suppose today is 2020-04-14
const targetDate = moment.parseRelativeDate("D0");
// 2020-04-14
const targetDate2 = moment.parseRelativeDate("D+1");
// 2020-04-15
const targetDate3 = moment.parseRelativeDate("D-2");
// 2020-04-12
// ISO dates are also supported
const targetDate4 = moment.parseRelativeDate("2020-05-15");
// 2020-05-15
Relative dates - moment.parseRelativeBusinessDate
Parse D-* notation (D0, D-1, D+1, etc) using only business days
// Suppose today is 2020-04-14
const targetDate = moment.parseRelativeBusinessDate("D0", "brasil");
// 2020-04-14
const targetDate2 = moment.parseRelativeBusinessDate("D+1", "brasil");
// 2020-04-15
const targetDate3 = moment.parseRelativeBusinessDate("D-2", "brasil");
// 2020-04-10
// ISO dates are also supported
const targetDate4 = moment.parseRelativeBusinessDate("2020-05-15", "brasil");
// 2020-05-15