Hi Observable.
We have a snow day here in Washington DC, which prompted me to ask how one would remove holidays from a date range [check out Mike’s recent tool: How many days since?].
Scouring the Internet, I find several articles and examples using jquery and moment.js, but I’d like to avoid using anything but pure JS, or, if anything, to use d3.js.
As a pure JavaScript, lsmith’s addBusinessDays script has several examples with relatively little code.
EDIT: As noted below, this is perhaps not the best example, as it appears not to calculate dates within a range. Here’s another StackOverflow example, which Ii have been similarly unable to get working, but for different reasons
In playing around with these examples, there are a few concepts that continue to challenge me. In the lsmith examples, The code seems to do this by extending the the core function with some additional parameters after a .
[e.g. functionName.otherParams
]. I believe that these extensions reference back to the main code if one is to separate them out into independent cells, but I get different errors depending on if I run a cell after manipulating it vs. when refreshing the notebook. If I just paste in the entire code block and flank the cell in curly brackets { }
, I get only undefined
.
In the stack overflow example that I added with this edit, I can’t get the dates variable to work because of what appears to be a syntax error. I’ve tried some different formatting options on the dates, but to no avail.
Here’s where I’m at:
https://beta.observablehq.com/d/b1365ed431f917cd - as a general playground with a few working examples at the bottom, and my attempts breaking down codes with ‘subsections’ at the top, and
https://beta.observablehq.com/d/369a4c679257d641 - which reflects the errors I am getting with data formatting.
Any pointers on how to take the next step? Insights into how to understand the ‘main’ part of a function and it’s ‘subsections’, and how to appropriately connect them? Sorry that I don’t really know the terminology for this…
Thanks in advance for your time and insights!