6 ms·
Years ago in a competitive programming contest, there was an interesting problem to calculate the number of days a bus runs in a given year and a given bus sche
by kccqzy 3y ago
Years ago in a competitive programming contest, there was an interesting problem to calculate the number of days a bus runs in a given year and a given bus schedule. The bus schedule could contain things like, the bus only runs on weekends, or the bus only runs on weekdays that aren't holidays, or the bus only runs on holidays but including the observed holiday which is the weekday after the holiday if the original holiday falls on a weekend. You know things are intense when you are programming a computer to perform the Computus (calculation of the date of Easter).
Technologists thought, how easy it is. A year has only a few hundred days, and there are only a few dozen possible rules for buses. Brute force is enough.
Nobody got the problem right. It gave me a great appreciation for how complex when technology interacts with culture and customs, long before my professional career.
- Scoundreller 3y agoAt least in North America we get every observed holiday on every year. There are places (hi France) where if it falls on Sat/Sun and if you're a M-F employee, you just don't get that holiday that year. Of course you have a pile of vacation time to use if you want.
- zoover2020 3y agoDoesn't France come with 25+10 holidays, though?
- Scoundreller 3y agoThe +10 (or whatever it is) fluctuates by year is my point.
- zoover2020 3y agoI'm not talking about public holidays, but turns out it's 2.5 days for each worked month - so 30 per year excluding the public ones
- pyrale 3y agoIt's 30 days including saturdays, or 5 weeks ; which means it's actually 25 days.
- pyrale 3y agoNo. It's 25. Th +10sih comes if you work more than weekly hours, or if you have a day-based contract (i.e. you don't count hours). Most day-based contracts are written saying "you owe x days to the company in a given year", so a holiday on a weekend becomes irrelevant.
- epolanski 3y agoIn Italy you always get compensated for those holidays, always, either with money (so you're paid an additional day) or additional vacation days.
- NovemberWhiskey 3y ago>At least in North America we get every observed holiday on every year. Ah, but that's not so. For example, if New Year's Day falls on a Saturday, then the NYSE doesn't observe the following Monday as a holiday - happened in 2022, for example.
- Scoundreller 3y agoah, thanks for reminding me. I had some Canadian investments to move that day, and I could see if it made sense to move it at the "frozen" price that day (Canadian markets were closed), or better to wait for them to drop the next day. Saved me tens of tax dollars!
- Kon-Peki 3y agoLook up NYSE rule 7.2 - a public holiday that occurs on a Saturday is typically observed on the Friday prior to the holiday, except in cases where that would interfere with quarter-ends and other unusual circumstances. This is why the New Years Day observance is sometimes skipped - December 31 is a quarter-end. They also avoid being closed more than 3 consecutive days, which is why they are open for trading on Black Friday (but they do close early!).
- vasco 3y agoI know our american friends live to work but 25 days vacation isn't even that much.
- robertlagrant 3y agoIt's a lot less than 365, it's true.
- vasco 3y agoI could've expanded but for senior engineers or managers in europe it's generally easier to get better vacation packages even before adding in public holidays. I know I value extra 10 days of vacation more than like $50k/year extra on my salary.
- vundercind 3y agoMost Americans have something like 0-15 paid vacation days.
- contrarian1234 3y agoDumb tangential question When you guys quote salaries in monthly figures.. Is the hourly rate fluctuating month to month based on the number of weekends and holidays? Or it vis a vis some standard amount of work days?
- pchangr 3y agoYou usually calculate it on a yearly basis. Yearly wage / yearly hours works
- Ekaros 3y agoAlso in Finland your effective hourly rate can fluctuate by year. That is if your salary is monthly. Depends on sector, but the hours worked depend on things like if you do shift work.
- kristjansson 3y agoRate tends to be set annually and prorated monthly or biweekly. Bills tend to be monthly, so the latter is kind of a PITA.
- AmericanChopper 3y agoDates are a nightmare even before you start accounting for public holidays. There’s a whole bunch of calendar and Timezone changes, and valid dates and times that simply don’t exist. Early in my career I had a bug that involved some date in February 1923 not occurring in Greece. I think I eventually fixed it, but I was never 100% sure.
- macksd 3y agoOohh interesting. From the Wikipedia article on February, 1923: February 28, 1923 (Wednesday) The nation of Greece used the Julian calendar for the last time before adopting the Gregorian calendar, used by most of the world, the next day. In that the Julian calendar was 13 days behind the Gregorian, the day was noted as "February 15". The next day was March 1 rather than February 16.
- lisper 3y ago> You know things are intense when you are programming a computer to perform the Computus (calculation of the date of Easter). Seems like that is a red herring since Easter is always on a Sunday, which, it seems to me, is all that could possibly matter given the description of the problem.
- djbusby 3y agoWhich Sunday? Just glance at Wikipedia to show it's not that easy. https://en.m.wikipedia.org/wiki/Date_of_Easter https://en.m.wikipedia.org/wiki/Date_of_Easter
- lisper 3y agoSure, the Sunday it's on moves around, but why would that matter? You're just trying to count the number of days the bus runs during a year under conditions like it runs/doesn't run on holidays/weekends. Easter is always a holiday, and always on a weekend. Under what circumstances would it matter which weekend?
- zie 3y agoHow we solve that problem is a Calendar table in the DB, and some human somewhere is required every year to update the calendar with the various holidays and what not. Then we just look up if it's in the list or not. It's a human problem anyway, and then when someone decides, wouldn't it be spiffy if we did a day of staff training on X day and did a reduced service? Sure, whatever, just put it in the calendar and blamo, accounted for properly.
- wredue 3y agoThis is also how we do it, but it’s the “obvious” solution the moment you realize that holidays don’t fall on the same days each year. It’s simple enough to predict the day they’ll fall on, but why bother with that when it takes someone 2 minutes every year to just enter these days in?
- xwolfi 3y agoAnd then some king dies in some country and it's a national holiday the next week, and the data entry guy is in sick leaves and your table isn't updated to close trading... happened to the bank I work in, wasn't funny.
- thowawatp302 3y agoI don’t think there’s an algorithm accurate enough to predict the death of that king down to a specific day. You’re still going to need that data entry guy. (Plus the two more that is the root problem)
- adrianmsmith 3y ago> Technologists thought, how easy it is. A year has only a few hundred days, and there are only a few dozen possible rules for buses. Brute force is enough. > Nobody got the problem right. It gave me a great appreciation for how complex when technology interacts with culture and customs, long before my professional career. For those of us who weren't there, could you let us share in that appreciation: why wasn't brute force enough?
- staunton 3y agoIt sounds like the problem wasn't so much "brute force" rather than the difficulty of completely understanding and specifying how holidays work...
- RandomLensman 3y agoVarious exchanges etc. publish their holiday calendars and you wouldn't/couldn't calculate them (there are also vendors for calendars).
- ildjarn 3y agoIs this stuff well handled using calendar libraries? I think the Microsoft one for .NET is pretty formidable.