Python Forum
Appropriate data-structure / design for business-day relations (week/month-wise)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Appropriate data-structure / design for business-day relations (week/month-wise)
#1
Hi guys,

I'm just trying to figure out "the best", i.e. cleanest and most appropriate way to do the following:

For a specified day, e.g. thursday, 22th of April 2021, I want to know / calculate: Is it the last working day of the current week, if not, what is the last working day of the current week? The same for whole month. And what's more: I want to know what was the last working day of the previous week (e.g. Friday, 16th of April) and the previous month (e.g. wednesday 31th of March).

As a basic condition, only Monday - Friday are working days, and on top of that, I have a list of days which I define as non-working days, which could be days during the week, or also at the end.

E.g. in case I define Friday [30th of April] and [Wednesday and Thursday 5th/6th of May] as non-working days, when I input [Tuesday 4th of May] into my algorithmn, it would say: [7th of May] is the last working day of the week and Thursday 29th of April was the last working day of the previous week.

What would be the "best" data-structure to handle this?
Is there a known algorithmn or even a suitable package which could be used?
In case no, I was wondering whether it makes sense to have some sort of pre-calculated list which are somehow interconnected, e.g. like a graph.

E.g. in a graph: Every day would be a node and be connected to the previous and the next working day nodes, it is connected to its working week (e.g. CW22), which, again is connected to its month. Every week and every month has a previous and a next week/month node.

By doing so, I would only have to search the node for a specific day, e.g. 22th of April, and from there, I could go to the week-Node the day belongs to, from there to the previous week-Node and from there to the last working day Node of that week-Node.

I'm just not clear whether I'm thinking way to overhead here!?

Thanks so much
Reply
#2
no need of elaborate data structure. this could/should be done by working with datetime objects and with simple calculations. Of course the list of the additional non-working days will be in a data structure.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
How can I get the last working day of a particular week or month using a customized list of non-working days without just iterating in reverse until I find the appropriate day?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  get list of dates in past month, current and upcoming month jacksfrustration 4 474 Feb-03-2024, 06:37 PM
Last Post: deanhystad
  Python Resampling: How do I obtain the value of the last week of the month? JaneTan 2 971 Dec-12-2022, 12:49 AM
Last Post: JaneTan
  Element wise computation divon 2 1,500 Jun-01-2022, 02:36 AM
Last Post: divon
  How can I add certain elements in this 2d data structure and calculate a mean TheOddCircle 3 1,501 May-27-2022, 09:09 AM
Last Post: paul18fr
  Print first day of the week as string in date format MyerzzD 2 1,979 Sep-29-2021, 06:43 AM
Last Post: MyerzzD
  what data structure to use? Winfried 4 2,783 Mar-16-2021, 12:11 PM
Last Post: buran
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 7,557 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  How to use Bunch data structure moish 2 2,830 Dec-24-2020, 06:25 PM
Last Post: deanhystad
  Generating random business cards Inkanus 2 2,151 Dec-08-2020, 09:41 PM
Last Post: buran
  Correct data structure for this problem Wigi 13 4,499 Oct-09-2020, 11:09 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020