Skip to content

striped/time-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🇺🇦 STAND WITH UKRAINE


"russia" and its accomplice "belarus" invaded Ukraine in 2014. This is an act of unprovoked aggression and is something unspeakably disgusting for me personally.

Adamant support of such unjustifiable actions by majority of the russian nationals indicates this is not just a one mad person problem; it is rather the nation level issue. It speaks loudly about ethics, culture and which values they possess. Objections about propaganda and autocratic governance isn't justifiable: all those committed by simple people, in name of whole nation consciously and by their free will. Thus, everyone identified as such are accountable for those actions no less than those involved directly.

Why "belarusian"? Because their damned country was used as for invasion and bombardment of Ukraine.

Thus, as author of this project, I shall ask the user to refrain from any usage / distribution / modification of any piece of this code:

  • by people who consider themselves as russian and belarusian,
  • by organizations, commercial and non-commercial that employ people who consider themselves as russian and belarusian.

Working day arithmetic & etc

This utility tool provides basic functionality for the calculation of the working days to the corresponding calendar date; namely translating working days into calendar dates and vise versa. Often it is necessary for business applications to follow only labour days, specifics to that or other religious or cultural traditions of the designated region.

Intention to offer this to the public was dictated due to the lack of such functionality in standard and / or widely adopted tools. Existing solutions are based on brute force iteration that is working well on short time intervals, but are linear and not efficient on middle to long ranges. Albeit, the simple arithmetic of such a calendar to a labour days translation is indeed simple and straightforward.

[Working day arithmetics] workweek for a traditional 5 days workweek (i.e. Christian) based on the following facts that are observed always and are true by definition:

  • Each year has the exact number of weeks, 52,
  • Each week has 7 calendar days,
  • Each week has 5 working days.

Thus, translation between the calendar and the working days might be as trivial as the relation observed as a stepped integer dependency between days devoted to labour and the calendar days. Indeed, it is essentially sufficient to add the weekend each time when the number of calendar days exceed the working week length. Saying that, the formulas for the traditional five working day week translations should look like:

$$<Calendar Days> = ⌊ (<Day of Week> + <Working Days>) / 5 ⌋ * 7 <Working Days> = ⌊ (<Day of Week> + <Calendar Days>) / 7 ⌋ * 5$$

The similar thoughts can be applied for any other existing workweek: 6 days per week or with sabbath that falls on Friday and Saturday only. Albeit, small adjustment to the calculations is necessary to make the stepped function to work when the numerical value of the weekend's <Day of Week> doesn't fall to the end of the week. However, all such calculations might be done in constant time, without looping through all the days in question to check whether it is a labour day or not.

However, the holidays can't be calculated as easily as above. Some of them don't have a fixed calendar date and are floating from year to year. For instance, Easter is observable on the first Sunday after a full Moon occurring on or after a Spring Equinox. In terms of Gregorian calendar this day varies between 22 of March and 25 of April. Albeit, the exact day is possible to calculate, such exercise will not be satisfactory, given it is the only holiday beside many, across different cultures and traditions. Another aspect of this matter lies in how such details would be used for the translation of working day(s) into the calendar. The solution discussed above helps to consider weekends in the required calendar period and for holidays it would be sufficient to check how many days between the start and the end of calendar dates. Thus, the static dictionary approach would look suitable in such circumstances. To simply check how many holidays fall into a questionable calendar interval, we may adjust it to satisfy an arbitrary number of requested working days. This "holiday dictionary", implemented in a form of balanced BST, would do this in the logarithmic time for an arbitrary chronological period, limited only by business requirements and / or the available heap. Once loaded and balanced, it can be used many times, within guaranteed computational complexity.

Releasing

The project is under Maven build tool thus, the whole releasing process is standard routine well described in maven plugin. After the artifact can be promoted to Central repo as described here.

See also