- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
The various holidays can be calculated, but it's neither easy nor straightforward for a lot of them. To see how to do it, look at the formulas in the AltCal spreadsheet.
Admin
He could have used Lewis Carroll's method, which would be a WTF all it's own...
In pseudocode:
Given CCYY/MM/DD...
E = (3-((18-C) MOD 4)) * 2
F = E + ((Y DIV 12) + (Y MOD 12) + ((Y MOD 12) MOD 4))
if (Monthname_in_english_begins_or_ends_with_vowel)
{ G = F + (10 - M) + days_in_month_ignoring_leap_years }
else { G = F + M }
if (CCYY is a leap year AND MM = (1 or 2) ) then W = G - 1; else W=G;
switch (W MOD 7) {
case 0: Sunday
case 1: Monday
...
case 6: Saturday
}
Or just do what everybody else does and use some standard free date calculations library to do it for you.
Admin
Well, I don't do Excel formulas, but here's a fun one:
Easter is on the first Sunday after the first full moon after the spring equinox. For any given Y = four digit year (now and in the future.. don't ask about those previous to the 1700's and such):
(all calculations are integer only, no remainder... DIV's, basically)
c = y / 100
n = y - 19 * ( y / 19 )
k = ( c - 17 ) / 25
i = c - c / 4 - ( c - k ) / 3 + 19 * n + 15
i = i - 30 * ( i / 30 )
i = i - ( i / 28 ) * ( 1 - ( i / 28 ) * ( 29 / ( i + 1 ) ) * ( ( 21 - n ) / 11 ) )
j = y + y / 4 + i + 2 - c + c / 4
j = j - 7 * ( j / 7 )
l = i - j
m = 3 + ( l + 40 ) / 44
d = l + 28 - 31 * ( m / 4 )
M and D will then be the month and day of Easter.
Admin
System.DateTime easter = dtmJesusDied.Date.AddDays(2)
Admin
Uh, just follow this link, then have fun writing the code yourself: http://www.oremus.org/liturgy/etc/ktf/app/easter.html
Admin
True, but most companies don't neccesarily follow the "official" rules, and may insert holidays of their own. (Anniversary celebration, industry conferences, etc.) What you're really interested in with a calendar like this isn't when the holidays actually occur. It's which days the plant will be closed, and that's sometimes a management decision, not a raw calculation. For instance, if the company offers X holiday days per year, but if several of the core holidays (Independence Day, Christmas, New Years) happen to fall on weekends, they may choose to actually observe the holiday on a convenient weekday. "Convenient" may not be calculable, unless the company has some kind of rule such as "closest working day to holiday shall be made a holiday".
Admin
>> 365 bytes, what a waste! Packing it to one bit per day would reduce it to 46 bytes
Actually that's sort-of how we do it, except with one row per date that contains a huge bitmask of holidays, one bit per financial center. An entire date range gets cached for computation and masked for lookup.
In banking/finance having an accurate and fast way to determine a good business day (past or future) is crucial. Consider that good business days vary widely not just from country to country, but sometimes city to city, or depending upon the definition of a "financial center", or even bank to bank or department to department. Even weekends aren't the same in the middle-east.
The definition of what's a holiday must be configurable by the organisation (so you can't rely on a standard API), be variable according to number of factors (currency/financial center), and be looked up fast (for millions of valuations on complex transactions you can't use on a SQL query to check each holiday).
So this is still a WTF, but only because it's sub-optimal.
Admin
The best solution is to use a web cam, point it at a calendar, use a robot to manually flip the pages of the calendar, use OCR to determine which days are holidays and write the results to a CSV file.
This CSV file should be propagated to several load balanced web servers and the results will be wrapped in SOAP functions where you call a isHoliday(DateTime) web service.
Now, the DateTime value that you pass in should based on the GMT time even if you are in a different time zone.
The web service returns a trinary variable, true, false, or FileNotFound.
Admin
Silly Marvin_Rabbit. Easter is a Sunday.
Admin
Go ahead and use a formula to help you add entries to your holiday table, but to not store it anywhere and rely on dozens of calculations like these "on the fly" probably isn't the most efficient way to go, is it? Do you really feel that this is "better" than simply storing the value in a table? Ironically, you will end up using more space just to store and the *formulas* for these holidays rather than probably 10-15 years of actual data !
Admin
Why? It's a Sunday anyways.
OK ...
dteEaster = dteGoodFriday + 2
Admin
Who told you it means Yes and No? You assume too much.... it's actually:
(Yikes, Work!)
and
(Now it's PARTY time!)
Admin
For most practical purposes, you need more than the official holidays... if management gives Dec 22, 2006 off as a christmas present for the staff, it's not an official holyday but must be considered for work planing. Next year it might be Dec 21; in 2008 there might be no such present because there is too much work to be done. No find a formula for that.
Admin
In my particular need it was only necessary to create the formulae once (maybe 30 minutes of work), loop through and populate tblHoliday from 1973 to 2073, therefore covering all of the years I expect to be alive, and thus accountable for the systems. HR gave me an exact list of our holidays and now I can program my digital wrist watch to disable the 7 AM alarm on those days.
Admin
Keep this under your hat, but I think his signature was a joke:
http://en.wikipedia.org/wiki/Joke
Admin
Here's a detailed explanation from the US Naval Observatory, which has the exact same formula - and an actual citation for the calculation.
Remember kids - your sources should be cited!
http://aa.usno.navy.mil/faq/docs/easter.html
Admin
VERY NICE!! I'm grabbing that one for my function library!!
Thanks!
Admin
I wonder if the holiday extraction routine used something like Oracle's "instr" based on the Database's "Day of the Year" calculation, or if it had to retrieve the whole string and parse it.
And if I were to write such a routine, I'd hope that I'd use a richer information model (I've got at least 26 characters, I can embed a lot of information about what holiday it might be e.g. N=New Years, M=Memorial Day, P=Presidents Day, V,X=Christmas Eve and Day, B=Boxing Day, Y=NYEve, A,U=sAt,sUn, W=normal workday, etc). And perhaps a test for "NULL" in the code with a best-effort at the main holidays (corporate declared holidays unavailable) ... with appropriate documentation and disclaimers.
Admin
It might also be a good approach if it turns out the calculation is not a bottleneck.
Admin
The programmer who wrote this doesn't have the sense he was born with A simple set of questions are needed to decide on updating policy.
Therefore, slap up a table and an editing screen, let the end-users deal with it and be programming something cooler in 2 years time.
If I want to appear indespensible, I make sure I'm vital for the high profile projects. Not holiday tables!
Admin
Layer upon layer of unfounded assumption go into this discussion. Maybe the app using this table cares about Easter (or a day near Easter); maybe not.
Maybe the "exact formula" for each holiday is applicable; maybe not. Last couple years, Christmas and New Years have fallen on the weekend. How arbitrary is the decision of which day we didn't have to work at my office? Well, this last year, the decision CHANGED (from the Friday before to the Monday after) mid-December.
Point being, in many business situations, the "holidays" must be treated as data, not code.
Exactly how poor the table structure/usage is depends on how the data will be accessed. I can't think of many cases where this is a good structure to use in a database table, because it strips away the advantages of the database -- i.e. the DBMS's ability to perform the operations on the data for which the DBMS was designed. A better approach might be to store holiday dates in the table, then at app init time, load the relevant range of dates and build a bitmap (or bytemap, I suppose) in memory. This would at least make maintaining the table a little less evil.
The problem of populating for the future... well, I can understand initially only populating a few years into the future (for the same reasons I cited above to explain my view that dates are data, not code). This type of table creates a periodic maintenance task by its nature; the problem is that apparently there's not even an automated reminder that the table's about to run out of data, much less a useful maintenance interface.
Admin
Ok.... and how do I find Good Friday?
dteEaster - 2 ?
Admin
God, that's awful.
And you still have to write some nasty SQL to get the data back out:
<font size="2">declare @dateToCheck datetime
set @dateToCheck = '12/29/1995'
/* use the offset in days into the year as the array index */
select substring(blnaryHoliday, datediff(dd, convert(datetime, '1/1/' + cast(year(@dateToCheck) as char)), @dateToCheck) + 1, 1)
from tblHoliday
where intYear = year(@dateToCheck)</font>
Admin
What about Easter?
"Easter Sunday is the Sunday following the Paschal Full Moon (PFM) date for the year. "
VB code (copied from http://www.assa.org.au/edm.html#Method):
How about custom Holidays like parent-teacher conference day in a school system?
Admin
Oops, sorry. I giot all excited and replied before I read page 2 and saw that a million other people already posted Easter.
Admin
It would have been much better to use 1111!!!111111111111!!!!1one!!11!onehundredandeleven.
Admin
It's not as bad as all that.
<font size="2">select
substring(
blnaryHoliday,
datepart(dayofyear, @dateToCheck),
1
)
from tblHoliday
where intYear = year(@dateToCheck)</font>
It's likely that there's a Calender.aspx page somewhere that shows a month or even a year at once. This could retrieve the single row for that year and split it into a character array for easy lookups.
Admin
You are all making it harder than it really is.
Good Firday is the day before the end of passover. Easter is the day after.
Passover is ALWAYS the 21st day of the first month. (Exodus 12:18 - look it up if you don't believe me)
See how easy that is? (Just switch everyone to the Hebrew calender and things will be much simpler, (Other than the leap month they throw in every few years)
Admin
Admin
No no no, when the Catholic hating Protestant religions banned the practice. In short back in the 1600s. (There are still a few left that have nothing to do with Christmas, but most have given in - the celebration may not be biblical, but everyone thinks it is)
Admin
if you ask the question can i book a holliday on X day it makes more sence =)
Admin
Noobs. Use PHP:
$easter = easter_date();
i'm not kidding
http://au3.php.net/manual/en/function.easter-date.php
Oh and Richard Nixon (if that IS your real name :p)
"Mayonnaise is generally said to have been created by the chef of Louis François Armand du Plessis, duc de Richelieu in 1756, to celebrate the Duke's victory over the British at the port of Mahon"
Admin
I found this site about 3 weeks ago, been reading a lot of the wtfs. Very entertaining stuff, lots of funny/insightful comments.
...and I'm fucking dumbfounded that little shits like the inimitable "Paula" or other mouth-breather wank-offs like the one responsible for this wtf actually continue to get paid for their incompetence when I can't even get a fucking interview.
And yes, I'm much, much, better than the morons responsible for the "topics" discussed here, and no, that isn't saying much.
The real WTF is that there are fuckups out there who are so incompetent at design/programming/development/basic problem solving that their profession is not developing software; it's being a fuckup.
And they get paid for it.
And I can't even get a fucking interview.
Un-what-the-fucking believable.
Admin
brillant!
Admin
Better yet:
$days = array("TRUE","TRUE","TRUE",......"TRUE","TRUE","TRUE","FALSE")
rawurlencode(base64_encode(serialize($days)))
Admin
BAH! HAMBUG!
Answer:
(when companies started to scrooge around for cheap programmers)
Admin
"It's a Feature" wrote:
> Most holidays can be mathematically calculated (3rd Monday of January, for example,
> for Martin Luther King's birthday), but some are rather complex in their formulas
> (every try to calculate Easter?)
There is perfectly good source code freely available for computing Easter Sunday. From this date, all Easter-related holidays can be easily calculated.
Been there, done that.
Admin
Well, some month ago I actually did something just like this -- when I looked at it I first thought some of my colleagues'd sent it in :) Trying to protect the original author and, OK, even myself: there are situations when it perfectly makes sense to use such a scheme. The company I'm working for provides transport and relocation services for mostly European and Amercian customers (using the Gregorian calendar) in around 10-20 countries in Asia and in the Middle-East (sometimes using totally different calendars), and these customers and the management here just wants to know when not to travel in those countries to do businness. And when you have countries like Afghanisthan, where they have single-day weekends on Fridays or Uzbekistan with "the second Wednesday after the first blossom of the sacred Oak"-type holidays, or even Hungary here, where they tend to create 4-day weekends upon govermental decision made some months before by working off the previous Saturday when a public holiday is on a Tuesday or Thurstday in the picture, it gets a bit more complicated than to use getDateofWeek() to find out if a day's a weekend or not. So, you have the choice of either buying expensive yet not guaranteed-to-be-correct public holiday databases from various suppliers (supposably employing some monkeys spending their days fetching all the information from obscure govermental sites), or can get your local office managers (who really should know all this stuff to plan their businness) to manually tick in the holidays at the beginning of each year or when their date gets fixed. Sure, they have "copy from previous year" and "preset weekends" features, but in the end, days will have to be picked one-by-one.
And even the uses of this table confirm the use of a bitmap-like structure: it gets used in calendar-like displays (which should simply get a holiday/not holiday like information for each day); and holiday-measuring and tracking for the company's employees, which is so complex anyways due the part-day calculations (gosh, they needed 0.01 workday precision and I had to consider coffee and lunch breaks!) and the potential need to join this with the punch system information using some fuzzy logic that it couldn't practically be done in SQL queries, only in program code -- which also needs bitmap-like data.
So, for me, it's not such a big WTF at all out of context like here. Or maybe I'm just trying to convince myself that I did not do something worth a Daily WTF post -- at least I really had to tell myself "yeah, I know it's ugly but it really makes sense here" for hours back then before finally implementing this :)
Admin
Absolutely.
Sad that I had to browse the whole first side of comments to find someone who understood some of the reasons why this might be a good idea and not a WTF at all.
Although I don't think this is sub-optimal. It would be easy for a non-techie to understand and even edit this field as-is as necessary, rather than needing any fancy calander tool.
I really can't see the WTF here folks.
Admin
A non techy screwing around directly in the database? Oh now that's a good idea... And how would the non techy do that without a fancy database tool? Via the command line and directly with SQL statements? Oh you might say they can enter that data into a text file, excel or word file and then you'd have a tool to insert it into the database, but why not write a good tool, which supports entering holidays (maybe with pre-picking fixed ones and so on), in the first place? Yeah, there are situations where you can't get a good tool to be used because your partners/customers are to stubborn or whatnot, but that doesn't make the approach less stupid. It just get's a necessary evil to use stupid ways to do things O_o
BTW:
Storing this information as Y and N doesn't help the readability in my book. Proofreading after you're done to check if you didn't do mistakes must be horrid. But that's just another story...
Admin
Easter is not a problem because it's by formula (it's not astronomically defined - the equinox and full moon in question are defined by formula).
That said, then you have to deal with the churches who use the revised julian calendar, celebrate Epiphany, and have easter on a different day. Fortunately the revised julian calendar is otherwise identical for the next couple hundred years.
Then you get a lot of calendars which are calculated astronomically (such as the Chinese one). And a whole lot of calendars are calculated astronomically (the lunar ones, for one), so Islamic holidays can't be calculated by formula indefinitely, though you may find one that seems to fit for the next howevermany years.
And then you have leap-months. Depending on which rules you calculate those by, your holidays may be off by an entire month.
CAPTCHA=BOZO
Admin
True enough. Although, as others have pointed out, this isn't really a WTF (with the possible exception of using 'Y' for workdays in a column described as 'binaryHoliday'). There are very good and valid reasons for storing this, not least of which is the need to deal with arbitrary holidays that can't be calculated.
It's missing any kind of country / financial centre indicator, so it probably only ever had to deal with one country - again, not really a WTF. And it obviously doesn't deal with half-day holidays terribly well (unless they have 'M' and 'A' flags, which would seem a reasonable approach, although unlikely to make binaryHoliday a more useful name than it already is).
I've seen stuff like this before, it's a compact, useful and relatively efficient way of storing stuff. Add a couple of stored procedures for querying a particular date and setting holiday status for a particular date and you don't ever need to worry about it again. Just go off and program something interesting.
Misnamed column using RPN. What's the fuss all about?
Simon
Admin
This is only the 1st page of about 353,000 returned by Google
http://users.chariot.net.au/~gmarts/eastalg.htm
Any holiday that's defined like "nth something after nth something" (like 2nd Monday of May, or 40 days after something else) can be calculated.
What's trickier are local holidays, probably any little town have at least 1 local holiday per year.
And if your company is multi-national you have to know about holidays in other countries too.
And than, we have things like half-holidays (you only work in the morning), this can happen (or not) if an holiday falls in a Friday, much of the times this is decided only a few days before.
Ant there's things like bank holidays, where only the banks are closed.
So you'll have to know the type of holiday too.
New holidays pop up, others are removed... The only way is to have a holidays table like:
MMDD HOLYDAY_TYPE DESCRIPTION COUNTRY PLACE
If you keep tables about local holidays most of this table can be filled by program on January the 1st but there will always be the need to hand edit the data.<o:p></o:p>
<!--[if !supportEmptyParas]--> <!--[endif]--><o:p></o:p>
Admin
You know, thats an explanation in itself...
Admin
or
declare @date datetime
set @date = getdate()
select substring(binaryHoliday, datepart(dy, @date), 1)
<FONT size=2>from tblHoliday
where intYear = year(@<FONT face="Times New Roman" size=3>date</FONT>)</FONT>
<FONT size=2></FONT>
<FONT size=2>Not that bad really.</FONT>
Admin
Sir! You just used a double negative! </fanboy>
Admin
Not even that...
The RIGHT name would be "tblWorkdays"
Admin
Booleanniversary?
Admin
Dammit, I quickly looked for a "dayofyear" function and didn't find it, so I assumed I was thinking of some other sql implementation. My WTF for reinventing that wheel.