Good morning, Does anyone have a magic wand function to calculate "working days" (if nowadays we can call that to the days from monday to friday) between dates? Adding to that, the ability to provide a list of holidays.
At times i've needed something like this too.. Previously we end up with a new data file containing each day in the year and let users then say Yes/No to each date for if its a working/manufacturing day or not. (But was mostly manual apart from automatically setting weekend to No)
It would certainly be nice to add such a capability to the Fndatetime.com utility function in the SOSLIB. But as you all well realize, the devil is coming up with a simple standard easily-editable data structure to distinguish “work” from “play” dates!
Maybe an international committee needs to meet in some secure location to work out the details?
Considering that, in this particular case, my starting and ending dates are always working days, I'm wondering if something near the following will do the job, probably needing to tweak a couple of results. WeekEndDays = Nr.Weeks x 2 WorkingDays = NrDaysBetweenDates - WeekEndDays
And to make it accurate, keep a list for hollidays and check how many are in the period. I have to play with the DATES function that calculate weeks to check the returned values, don't know, I'm writing on the fly but will be funny to play this.
Any additional thoughts are welcome and the post is already useful for suggesting secret places to discuss the theory.
It may need several more days at the secure location brain storm that thought!! But even then it may become even more complex if those days there start to lead in a "weekend"
Well don't ask Steve he is on holiday more than in the office!!
But in theory you could run a julian calendar routine from jan1 thry Dec31 and detect the day of week (being mon-fri) and just count those. As far as holidays well again, don't ask Steve!
This calculation is obviously going require a lot of nutritional fortifications to account for all these complications. Until we can get that meeting set up, I added an option to the Fn'Days'Ago() function in fndatetime.bsi so you can easily count the weekdays between two days. (Apologies in advance if that will require working holidays until the full version can be completed!)
Wow! I was about to start my day and decided to check if Joe had come up with some AI solution, but you have applyed that complex computation already, many thanks But I'm getting errors in the IDTIM and DATES for string input dates like "20250121", any clue?
Oops -- I did the typical American thing and failed to fully test it with non-American date format. Most of the functions in that fndatetime library do have options to specify the MDY vs DMY format option, but if not specified, they were defaulting to MDY rather than using the LDF format. I think that's fixed now in edit [168] of fndatetime.bsi. Please give it another try.
Jack, while searching for interesting functions in your fndatetime.bsi found there are two Fn'Date'Earliest() instead of Fn'Date'Earliest() and Fn'Date'Latest() Didn't even know that's allowed
I guess we are just ahead of the AI dept here as we have had a juliian->gregorian conversion routine for about 50 years now that automatically sets the day of week and week number.. which makes this about a 2 minute program to write
Starting with Jorge's observation: ouch! Unlike our blundering Defense Secretary, I take full responsibility for this failure! I would even offer to resign, but as it turns out, it took so long for the error to be discovered because it was in fact not a compiler bug. It did however expose a compiler secret (fortunately, not a classified one!) : the COMPIL /PX switch implements the "tree shaking" algorithm to remove any functions that aren't actually referenced, before real compilation begins. So in this case, the duplicate Fn'Date'Earliest() functions were both simply removed/ignored.
That feature(?) actually covered up another bug in that function, which the compiler would have complained about if the /PX switch had hadn't been specified: the return type of the function as declared was T_FLEX_DATE, which is defined in ashinc:types.def as:
Code
deftype T_FLEX_DATE = s,50 ! [116] (see Date Format Notes above)
In other words, the return type was a string. But according to our rules, a function returning a string result must have a $ suffix, so Function Fn'Date'Earliest(...) as T_FLEX_DATE would have triggered the ?Illegal function type override error if it had actually been compiled.
As you may have noticed in your browsing, there is a built-in testing front-end (created by compil fndatetime.bsi/x:2/m/px/c:FNDATETIME_BSI_TEST=1 that does contain calls to the Fn'Date'Earliest$() and Fn'Date'Latest$() functions, which both compile correctly and work as advertised (because they have the required $ suffix and aren't duplicated).
So thank you for pointing that out. I've removed the offending functions and reposted a new version [169] of fndatetime.bsi. And you've certainly earned a MicroSabio Pen at the next Conference (assuming I can obtain one of the remaining exceedingly rare ones at a future Christie's auction!)
Moving on to Frank: We always suspected you were smarter than you looked! Indeed, if you and Steve had only gotten together to establish the worldwide date standard 50 years ago, we could have redirected all that programming energy at solving a real problem, like world hunger or climate change! But then the world would never have experienced the joy of wandering through the treasure chest of conversion functions in modules like fndatetime.bsi . (Which in fact does convert the dates to an Julian-type format in order to calculate elapsed days.) And as you suggested, subtracting the weekend days from the overall elapsed days requires only a teeny bit of extra code/logic. Extending that to support a completely flexible list of non-working days would probably be best accomplished by creating a Fn'Load'Holidays(holidays()) function to load an open-ended calendar containing all the known non-weekend, non-working days into a static array holidays() of Julian day numbers, allowing it to be conveniently and efficiently passed as an option to the function computing working days between two arbitrary dates. It still needs a nice UI to allow the holidays to be entered into a calendar. (Another MicroSabio Pen to whoever puts that all together into an open-source function and presents it at the next Conference!)
As an aide to anyone attempting such a project without Frank's skills, here's a partial list of potentially helpful date manipulation routines and topics:
Forget dates and bugs and just let the bidding for this pen start! (Please not it’s still in the wrapper , unused, so I take no responsibility if opened and it falls into just dust)
Perhaps i should add glasses to get that "book smart" look?!
Isn't it a fools errand to calculate holidays? I mean based on what or who's definition of "holiday"?! It's not even consistent between employers! MLK day? President's day? Thanksgiving? I mean they celebrate Thanksgiving in Brasil?! No offense to Jorge but the premise is sort of unorthodox. And to have ashell provide this seems like an over-reach. This should be managed at the local/state/govt application level.
And now that Jack has done stepped in it I am afraid we should be expecting your resignation?!
Steve - opening that package would be like opening a 200 year old bottle of Romanee Conti - not only is the value destroyed, the contents have almost certainly gone bad! You might want to hold on to it a bit longer though, since the new tariff war is sure to drive the prices even higher!
Frank - actually I think the book smart look has gone out of style -- the new look is a goofy T-shirt with a sport coat and baseball cap. And yes, obviously having a standard holiday schedule is out of the question. But it might still be a reasonable idea to create a standard representation for a user-editable list of holidays so that it could be easily incorporated into standardized algorithms. (So maybe reports of my pending resignation are grossly exaggerated!)
Well I'm tempted to extend my collection of Microsabio pens and apologize for the absence of pictures, the banks are already closed to access my secret safe.
Frank, fortunately Brazil didn't adopt Thanksgiving (yet) otherwise it would be easier to fill the list of working days instead of the holidays.
I'll be happy to jump in that contest with my "unavailability list" handler Apologize for the portuguese labels, anyway it's an easy translation, any AI piece of code can convert the image into a translated one. In a short description, it allows to register unavailable slots of time for the purpose you need. It can be single days (yyyymmdd), periods, yearly days (mmdd) (eg Thanksgiving, Christmas) as well as fixed weekdays or half days (eg: if the company don't work on friday's afternoon).
There is also a customizable table for types of days like "national holidays", "regional holidays", "vacations" and so on, to identify the type of slot. This list is saved in an ISAMA table and there is Function to check how many unavailable slots exist in a period (I'm adjusting it right now for my current needs considering this module was written in 2007 and can be optimized).
I advise not exposing those pens to too much light (in order to take pictures), since considering their advanced age, the delicate pigments in the housing might fade, reducing the value.
As for your unavailability list handler, setting aside the possible complication of partial days, what's needed now is just a Fn'Load'Holidays(holidays()) function that loads up the auto_extend holidays() array, preferably using the XCALL DATES DTOP_CVTFMT B4 internal Julian date format (or the Fn'Date'To'JulianY2K version that reduces it to a B2 offset from 1/1/2000). That array could then be easily passed as an optional parameter to the Fn'Day'Ago() function, which I would be happy to update to factor the array of holidays into the elapsed working days calculation.
Jack - Well then, i have been way ahead of that curve for at least 10 years now!
Jorge - still don't understand why we are asking the operating system / programming language to provide this function. Just so I am clear, is this function avalable in other 3/4gl languages?
Frank, apologize, but I don't know what you mean about "we are asking to the operating system" what are we asking for? If you read from the initial post, I asked the community if anyone have written a function to count working days, after that we started to joke with non-related stuff and when I thought that we have closed the topic, on the fly, I came up with a draft for a function that could solve my specific needs and, for my surprise, Jack add it to an existing function, among dozens he wrote for the community, but SOSLIB is not operating system, is a collaborative library. What I find in those 3/4gl languages is an huge ammount of libraries where, almost surely, we can find useful and shareable stuff for all needs and that's what we are trying to get in our small Gauloise Village.
Jack , huuuuuummmmmmmm, now you got me, I don't know if I have enough strength to take that challenge
Understood - not being critical i just think simple tasks like these are easily written locally w/o the bloat of a large function of the programming environment (ashell).
Adding more functions to the SOSLIB doesn’t create any more bloat than adding books to the public library. And if it improves the chances of being able to ‘borrow’ what you were looking for, instead of having to ‘buy’ (write) it, what’s not to like?
But perhaps we have taken this idea too far, so Jorge, if you buy me a drink at our next meeting, I promise to never mention this project again!
Well Jack, you can count with several drinks on me as well as a nice bottle of some distilled with the promise to keep this topic hot and, I take the chance to invite Frank to join the group to drink and to improve the talk. By the way, Frank how are you and family? What is your current professional situation and plans?
Well that is a good analogy - but why goto the library when you can just get everything online?! Ok well enuf beating this horse glad Jorge got his utility and Jack lives to ride another day
Hey Jorge - thanks for asking. We are all well thanks albeit right now in a very serious wildfire emergency here. Hoping to not have to evacuate. Still working and supporting our customer base.