soar-tech / dayjs-business-days Goto Github PK
View Code? Open in Web Editor NEWDay.js plugin to add support for calculating dates only accounting for Business days
License: MIT License
Day.js plugin to add support for calculating dates only accounting for Business days
License: MIT License
Hi,
I'd like to open a PR so that one can set custom workingWeekdays. It seems I need to be allowed to open PRs, is there anything I should do in order to do so?
Is there an opportunity to use custom holidays?
Like it is in moment-business-days updateLocale
Hello, in the latest version of release, the code with holiday is not present.
So after the install by yarn, i wont be able to use isHolliday()
function.
Can you generate new release please ? ๐
var dayjs = require('dayjs');
var dayjsBusinessTime = require("dayjs-business-time")
dayjs.extend( dayjsBusinessTime);
const businessTimes = {
sunday: null,
monday: [
{ start: '07:00:00', end: '19:00:00' }
],
tuesday: [
{ start: '07:00:00', end: '19:00:00' }
],
wednesday: [
{ start: '07:00:00', end: '19:00:00' }
],
thursday: [
{ start: '09:00:00', end: '19:00:00' }
],
friday: [
{ start: '07:00:00', end: '19:00:00' }
],
saturday: null,
}
dayjs.setBusinessTime(businessTimes);
let start = dayjs('2021-03-05 20:07:10'); // next business day would be after 'end'
let end = dayjs('2021-03-08 10:07:10');
let difference = 0;
// if( ! end.isBefore(start.nextBusinessDay())) { //workaround
difference = start.businessTimeDiff(end, 'days'); // <--- crash
//}
console.log( 'Difference: ' + difference )
Thank you for your great work!
First of all, thanks for this library. It can be really handy.
Is there a way to use directly from the browser?
Recently I created my own dayjs plugin, dayjs-random largely using this plugin as a template.
While doing so I noticed that when importing this plugin using the cjs module format to be used on my server didn't quite work as expected.
const dayjs = require('dayjs')
const dayjsBusinessDays = require('dayjs-business-days')
dayjs.extend(dayjsBusinessDays)
This code results in the following error
....
TypeError: t is not a function
at Function.g.extend (C:\$Projects\dayjs-random-test\server\node_modules\dayjs\dayjs.min.js:1:6481)
at Object.<anonymous> (C:\$Projects\dayjs-random-test\server\index.js:4:7)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
In order to import it properly I had to add .default to the end of the require
const dayjs = require('dayjs')
const dayjsBusinessDays = require('dayjs-business-days').default
dayjs.extend(dayjsBusinessDays)
I'm getting a t is not a function
error when running dayjs-business-days in a nuxt3 ssr environment. I do not get this error when running dayjs as client only.
When doing the following, I get an infinite loop:
const x = dayjs(null).businessDaysAdd(1);
This is probably due to the while loop in the businessDaysAdd
method. It proceeds to the next day, reduces the days to add by one if that next day is a business day, and repeats until days to add reach zero.
When the starting date was invalid, no day will ever be a business day and the remaining days will never decrease.
My advice would be changing line 23 in index.js from
while (daysRemaining > 0) {
to something like
while (currentDay.isValid() && daysRemaining > 0) {
plus adding a test.
Published npm version can be outdated (like now)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.