Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@171h/dayjs-business-time
Advanced tools
A [Day.js](https://github.com/iamkun/dayjs) plugin that allows you to work with Business Time.
A Day.js plugin that allows you to work with Business Time.
isRealBusinessTime
function compared to the official v1.0.4
expect(dayjs('2021-02-11 17:00:00').isRealBusinessTime()).toBe(false);
expect(dayjs('2021-02-11 17:00:00').isBusinessTime()).toBe(true);
npm i dayjs-business-time
yarn add dayjs-business-time
// First of all, include dayjs
const dayjs = require('dayjs');
// Then, include dayjs-business-time
const dayjsBusinessTime = require('dayjs-business-time');
// Attach dayjs plugin
dayjs.extend(dayjsBusinessTime);
// Now you have all Business Time methods in dayjs
// First of all, include dayjs
import dayjs from 'dayjs';
// Then, include dayjs-business-time
import dayjsBusinessTime from 'dayjs-business-time';
// Attach dayjs plugin
dayjs.extend(dayjsBusinessTime);
// Now you have all Business Time methods in dayjs
By default, holidays are empty!
// Create your holidays array as string array
const holidays: string[] = [
'2021-01-01',
'2021-01-25',
'2021-06-03',
];
// Add holidays to dayjs
dayjs.setHolidays(holidays);
const holidays: string[] = dayjs.setHolidays(holidays);
console.log(holidays);
// Output: ['2021-01-01', '2021-01-25', '2021-06-03']
By default, Business Times are Monday-Friday, 9am - 5pm, but you can setup as many Business Segments you want in a day
// Create your Business Week definition
const businessTimes: BusinessHoursMap = {
sunday: null,
monday: [
{ start: '09:00:00', end: '17:00:00' }
],
tuesday: [
{ start: '09:00:00', end: '12:00:00' },
{ start: '13:00:00', end: '18:00:00' }
],
wednesday: [
{ start: '09:00:00', end: '12:00:00' },
{ start: '13:00:00', end: '16:00:00' },
{ start: '13:00:00', end: '17:00:00' }
],
thursday: [
{ start: '09:00:00', end: '17:00:00' }
],
friday: [
{ start: '09:00:00', end: '17:00:00' }
],
saturday: null,
}
// Set Business Times in dayjs
dayjs.setBusinessTime(businessTimes);
According to holidays setup
const isHoliday = dayjs('2021-02-01').isHoliday();
console.log(isHoliday); // false
Bussiness Days are days with Business Hours settled, excluding Holidays.
const isBusinessDay = dayjs('2021-02-01').isBusinessDay();
console.log(isBusinessDay); // true
Bussiness Times are all minutes between Start and End of a Business Time Segment.
const isBusinessTime = dayjs('2021-02-01 10:00:00').isBusinessTime();
console.log(isBusinessTime); // true
const nextBusinessDay = dayjs('2021-02-01').nextBusinessDay();
console.log(nextBusinessDay); // 2021-02-02
const lastBusinessDay = dayjs('2021-02-01').lastBusinessDay();
console.log(nextBusinessDay); // 2021-01-29
const nextBusinessTime = dayjs('2021-02-01 18:00:00').nextBusinessTime();
console.log(nextBusinessTime); // 2021-02-02 09:00:00
const lastBusinessTime = dayjs('2021-02-01 08:00:00').lastBusinessTime();
console.log(lastBusinessTime); // 2021-01-29 17:00:00
const day = dayjs('2021-02-01 10:00:00');
const timeToAdd: number = 2;
// Possible BusinessTimeUnit is 'day', 'days', 'hour', 'hours', 'minute', 'minutes'
const unit: BusinessTimeUnit = 'days';
const newBusinessTime: Dayjs = day.addBusinessTime(timeToAdd, unit);
console.log(newBusinessTime); // 2021-02-02 10:00:00
This method is just an alias for .addBusinessTime(timeToAdd, 'days')
const day = dayjs('2021-02-01 10:00:00');
const timeToAdd: number = 2;
const newBusinessTime: Dayjs = day.addBusinessDays(timeToAdd);
console.log(newBusinessTime); // 2021-02-02 10:00:00
This method is just an alias for .addBusinessTime(timeToAdd, 'hours')
const day = dayjs('2021-02-01 10:00:00');
const timeToAdd: number = 2;
const newBusinessTime: Dayjs = day.addBusinessHours(timeToAdd);
console.log(newBusinessTime); // 2021-02-01 12:00:00
This method is just an alias for .addBusinessTime(timeToAdd, 'minutes')
const day = dayjs('2021-02-01 10:00:00');
const timeToAdd: number = 30;
const newBusinessTime: Dayjs = day.addBusinessMinutes(timeToAdd);
console.log(newBusinessTime); // 2021-02-01 10:30:00
const day = dayjs('2021-02-01 10:00:00');
const timeToSubtract: number = 2;
// Possible BusinessTimeUnit is 'day', 'days', 'hour', 'hours', 'minute', 'minutes'
const unit: BusinessTimeUnit = 'days';
const newBusinessTime: Dayjs = day.subtractBusinessTime(timeToSubtract, unit);
console.log(newBusinessTime); // 2021-01-28 10:00:00
This method is just an alias for .subtractBusinessTime(timeToSubtract, 'days')
const day = dayjs('2021-02-01 10:00:00');
const timeToSubtract: number = 2;
const newBusinessTime: Dayjs = day.subtractBusinessDays(timeToSubtract);
console.log(newBusinessTime); // 2021-01-28 10:00:00
This method is just an alias for .subtractBusinessTime(timeToSubtract, 'hours')
const day = dayjs('2021-02-01 12:00:00');
const timeToSubtract: number = 2;
const newBusinessTime: Dayjs = day.subtractBusinessHours(timeToSubtract);
console.log(newBusinessTime); // 2021-02-01 10:00:00
This method is just an alias for .subtractBusinessTime(timeToSubtract, 'minutes')
const day = dayjs('2021-02-01 10:00:00');
const timeToSubtract: number = 30;
const newBusinessTime: Dayjs = day.subtractBusinessMinutes(timeToSubtract);
console.log(newBusinessTime); // 2021-02-01 09:30:00
const start: Dayjs = dayjs('2021-02-01 10:00:00');
const end: Dayjs = dayjs('2021-02-04 10:00:00');
// Possible BusinessTimeUnit is 'day', 'days', 'hour', 'hours', 'minute', 'minutes'
const unit: BusinessTimeUnit = 'days';
const difference: number = start.businessTimeDiff(end, unit);
console.log(difference); // 3
This method is just an alias for .businessTimeDiff(dateToCompare, 'days')
const start: Dayjs = dayjs('2021-02-01 10:00:00');
const end: Dayjs = dayjs('2021-02-04 10:00:00');
const difference: number = start.businessDaysDiff(end);
console.log(difference); // 3
This method is just an alias for .businessTimeDiff(dateToCompare, 'hours')
const start: Dayjs = dayjs('2021-02-01 10:00:00');
const end: Dayjs = dayjs('2021-02-01 15:00:00');
const difference: number = start.businessHoursDiff(end);
console.log(difference); // 5
This method is just an alias for .businessTimeDiff(dateToCompare, 'minutes')
const start: Dayjs = dayjs('2021-02-01 10:00:00');
const end: Dayjs = dayjs('2021-02-01 10:45:00');
const difference: number = start.businessMinutesDiff(end);
console.log(difference); // 25
FAQs
A [Day.js](https://github.com/iamkun/dayjs) plugin that allows you to work with Business Time.
The npm package @171h/dayjs-business-time receives a total of 2 weekly downloads. As such, @171h/dayjs-business-time popularity was classified as not popular.
We found that @171h/dayjs-business-time demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.