jamesplease / moment-business Goto Github PK
View Code? Open in Web Editor NEWUtilities for work days in Moment. (Western workweeks only.)
License: MIT License
Utilities for work days in Moment. (Western workweeks only.)
License: MIT License
var final = moment(date).weekDays(date2); if like this it isn't working
I know that holidays varies by country, state, city, province, etc
I think would be good have a way to set the holidays, with a array of month/date
For instance with the US federal holidays would be something like this moment.setHolidays(['January 01', 'January 18', 'February 15', 'July 04', 'May 30', 'September 5', 'October 10', 'November 11', 'November 26', 'December 26'])
For NY we would push some more days to the list: moment.addHolidays(['February 12', 'November 08', 'December 25'])
Them when we use methods of moment-bussiness
it consider these days not as weekdays, and not as weekendDays.
We can also create methods to count holidays.
What do you think?
I tried to use the lib without npm,
by copying the moment-business.js file,
and source it with:
<script src="moment-business.js"></script>
then use it with
import business from 'moment-business';
but I got error below:
Uncaught SyntaxError: Cannot use import statement outside a module
Any idea how to solve this ?
When I try to use this with moment timezone in typescript, it looks like both timezone and business have definition to the Moment but they can't convert to each other.
It's been a few years since I wrote this, but it's my most popular library by downloads. I should update it!
This won't involve any code changes, and no npm releases. It'll simply be a repository refresher.
would be a lot easier (and cleaner) if you would implement the method through the prototype.
moment().isWeekend()
is much nicer then bussiness.isWeekend(moment())
Might involve adding the code climate config file to the repo
addWorkdays
subtractWorkdays
It seems to currently be exporting as window.none
. Note that this only affects users who aren't using a module bundler like CJS, AMD, or ES2015 modules. If you are using those module bundlers, then you're good to go.
The following code returns an incorrect value for the number of weekend days:
const start = moment.utc("2016-07-25T13:43:00.000+00:00");
const end = moment.utc("2016-08-22T11:28:00.000+00:00");
business.weekendDays(start, end); // returns 7, expected 8
Is this right?
Often times when calculating week days I'd like more precision to be returned. Currently calculations less then one day get rounded down to zero. I would like to see a flag introduced to signal when to not round down. So we end up with possible values of 0.5 days or 7.3 days.
Is this possible without forking?
Thanks ๐
Seems like there is a problem at moment#diff
, used by the weekDays
method.
You can reproduce the same bug on moment-business with these tests: https://github.com/jmeas/moment-business/compare/jmeas:master...leobalter:return-proper-weekdays?expand=1
I didn't open a PR with these tests as they're not following the standard from the other tests, we could improve it.
I checked the return from the .diff call at weekDays and the off-by-one is happening there.
The comments in the fixtures weren't updated for Mon-Sat.
moment-business.js does not export moment
O(n) => O(1)
Please can you make the documentation in the README clearer for using weekDays and weekendDays - please make it specific that these have to be used endMoment.weekDays(startMoment)
Just been using this with startMoment.weekDays(endMoment) and puzzling over weird responses - it was only when I looked at the source that I realised what was going on.
business.install()
import 'moment-business/plugin'
Basically just updating the babel boilerplate
When using the weekDays function,
The result may + 1 day when the startMoment and endMoment are both weekend AND when the endMoment is weekend.
Here are some testing results:
console.log(momentBusiness.weekDays(moment('08-05-2016','DD-MM-YYYY'),moment('15-05-2016','DD-MM-YYYY')));
// Actual Result = 5, Expected Result = 4
console.log(momentBusiness.weekDays(moment('09-05-2016','DD-MM-YYYY'),moment('14-05-2016','DD-MM-YYYY')))
// Actual Result = 5, Expected Result = 4
console.log(momentBusiness.weekDays(moment('07-05-2016','DD-MM-YYYY'),moment('13-05-2016','DD-MM-YYYY')))
// Actual Result = 4, Expected Result = 4 <-- This is correct
@cowboy mentioned that there's not much reason for this to modify the moment obj. directly. I should just expose methods on an obj rather than modifying the moment prototype.
This thing has a lot of downloads. I should make it look more reliable ๐
I would like to use moment-business with TypeScript. Is there a d.ts available?
Thankx, Harry
When I do today.workDays( tomorrow )
where today and tomorrow are moments a day apart, I get Undefined is not a function
- is there something I am doing wrong?
.addWorkDays()
and .subtractWorkDays()
are working fine
I began trying to use this library for the addition and subtraction of week days. I never finished, though, and I should.
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.