moment-loyall
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.4.012latest

Version History

VersionDownloads (Last 7 Days)Published
1.4.012
1.3.022
1.2.100
1.2.96
1.2.8249
1.2.70
1.2.60
1.2.558
1.2.30
1.2.20
1.2.10
1.1.10
1.0.40
1.0.30
0.0.150
0.0.140
0.0.130
0.0.120
0.0.110
0.0.100
0.0.90
0.0.80
0.0.70
0.0.60
0.0.50
0.0.40

Package Sidebar

Install

npm i moment-loyall

Weekly Downloads

347

Version

1.4.0

License

ISC

Unpacked Size

913 kB

Total Files

27

Last publish

Collaborators

  • shadowlik