Comment On Time for a tblHoliday

For most, the New Year is great occasion: not only is it kicked off with a big bash, but it's so easy to trick yourself in feeling like you have a "clean slate", setting all sorts of great goals and resolutions, and just all-around feeling good. But for some programmers, like Dave Sussman, it's not so joyous of an occasion; each change of the year is like a mini-Y2K. These programmers are the guys who get to maintain systems with comments like ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Time for a tblHoliday

2006-04-06 13:57 • by IRRePRESSible
YES! I did it only took me 27 days

Re: Time for a tblHoliday

2006-04-06 13:58 • by ...
first.

Re: Time for a tblHoliday

2006-04-06 14:01 • by Ken Nipper
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........

Re: Time for a tblHoliday

2006-04-06 14:06 • by maldrich
Obviously done for extensibility. If you tie this kind of thing to tenuous structures like DateTime data types or Calendar functions, you'll be sorry when the calendar changes. Just think about all those programmers working when the Gregorian calendar came online. They were spending weeks recoding. Our friend here can just set a few bits and he's all set. You youngsterd think y2k was bad, you just don't remember y1582. Ugly, man. Ugly. Better to roll your own calendar functions than go through THAT again.

Re: Time for a tblHoliday

2006-04-06 14:07 • by rob_squared
This still doesn't match the amazing power that Microsoft has to reschedule Thanksgiving to fall on a Wednesday:

http://72.14.203.104/search?q=cache:RzFeU2G46_8J:blogs.msdn.com/jensenh/archive/2005/11/23/496246.aspx+microsoft+bug+thanksgiving+tuesday&hl=en&gl=us&ct=clnk&cd=2

Re: Time for a tblHoliday

2006-04-06 14:07 • by Casiotone
blnaryHoliday?

booleanary?

Re: Time for a tblHoliday

2006-04-06 14:08 • by marvin_rabbit
Alex Papadimoulis:
+---------+--------------------------------------------------------------------------+

| intYear | blnaryHoliday |
+---------+--------------------------------------------------------------------------+
| ... | ... |
+---------+--------------------------------------------------------------------------+
| 1995 | NYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNN |
+---------+--------------------------------------------------------------------------+

I also like that in a table tblHoliday, and a field named blnaryHoliday, that the days marked with a "Y" are NOT holidays.  Just another little bundle of joy.

Re: Time for a tblHoliday

2006-04-06 14:08 • by Saarus
This conversation probably happened a couple of years later, after the original developer moved to a new company:

Original Developer: "Yeah, so I didn't want to have to go through each calendar year and figure out weekends, weekdays, and holidays manually. So I populated this table auto-magically by writing a script to iterate over years from 1975, and figure for each day whether it was a weekend or holiday. Saved me loads of time."

Rookie: "Why didn't you just... you know... like, adapt the code from that script, instead of... well, instead of storing it in the database like that?"

Original Developer: "Ah! You are obviously new to enterprise development!"

Re: Time for a tblHoliday

2006-04-06 14:10 • by Anon
Man, I want to work for that company.  You only have to work for 2 days and then you get 5 holidays!!

Re: Time for a tblHoliday

2006-04-06 14:11 • by Suck My Lisp
67340 in reply to 67333
Because if you used logic instead of Ys and Ns you'd drastically increase the size of your database:



TRUETRUEFALSEFALSEFALSEFALSEFALSEFALSETRUETRUEFALSE

FALSEFALSEFALSEFALSETRUETRUE ...





Re: Time for a tblHoliday

2006-04-06 14:11 • by Sam
67341 in reply to 67333

Ken Nipper:
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........


I don't think "logic" is the way to go (not sure how you'd logically work out what the holidays would be, anyway -- plus, what happens when that "logic" changes?).  However, you could just put the dates in the table as dates, maybe with a nice little description for the holiday in a separate column.  Plus other column flags like which country it's a holiday for, or whether it's a trading or settlement holiday for finance, or whatever.


Of course, logic works for weekends.  Is it just me who only sees weekends defined on this chart?

Re: Time for a tblHoliday

2006-04-06 14:11 • by Mikademus
67342 in reply to 67339
That threw me off, why are the non-holidays marked "Y"?!

Re: Time for a tblHoliday

2006-04-06 14:16 • by Mihai
365 bytes, what a waste! Packing it to one bit per day would reduce it to 46 bytes!
And you still have 1 bit available to store other stuff, and 2 bits in non-leap years!

Re: Time for a tblHoliday

2006-04-06 14:16 • by maldrich
67344 in reply to 67342
Should probably be bInaryWORKDAY (Y/N)

Can't believe I am suggesting naming improvements for this nightmare. I guess I need something to do....

Re: Time for a tblHoliday

2006-04-06 14:17 • by Stephan
67345 in reply to 67342
The really funny thing is that it should be called "tblWeekends".

Re: Time for a tblHoliday

2006-04-06 14:18 • by jackass
And it works great overseas.  All you have to do is create a new table and determine other countries holidays.

Re: Time for a tblHoliday

2006-04-06 14:18 • by Colin
67347 in reply to 67342
Mikademus:
That threw me off, why are the non-holidays marked "Y"?!




You see, when you get to work with code like that....each work day is just like a holiday.  I'm so super jealous.

Re: Time for a tblHoliday

2006-04-06 14:19 • by orbis tertius
laughable... this fellow clearly has no idea about enterprise systems.

he should have had another table called "days", where each row contains the current date. a daily cron script can then kick off each day to add a row to the days table, which of course has a trigger that calls a stored procedure which automatically appends a "Y" or "N" to the proper row in blnaryHoliday.

Re: Time for a tblHoliday

2006-04-06 14:24 • by John Hensley
67349 in reply to 67348
A more "enterprise" way to do this would be with two tables:



one to enumerate holidays...



and one to enumerate non-holidays!



Re: Time for a tblHoliday

2006-04-06 14:28 • by DWalker59
67352 in reply to 67348
I agree -- there are NO holidays listed in that table, only the weekdays are marked Y.  Apparently there are no holidays, or else every weekday is a holiday.

Re: Time for a tblHoliday

2006-04-06 14:30 • by marvin_rabbit
67353 in reply to 67349
Anonymous:
A more "enterprise" way to do this would be with two tables:

one to enumerate holidays...

and one to enumerate non-holidays!


Ah yes, then you have truly mastered Zen Programming.

Re: Time for a tblHoliday

2006-04-06 14:31 • by ParkinT
67354 in reply to 67341
Anonymous:

Ken Nipper:
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........


I don't think "logic" is the way to go (not sure how you'd logically work out what the holidays would be, anyway -- plus, what happens when that "logic" changes?).  However, you could just put the dates in the table as dates, maybe with a nice little description for the holiday in a separate column.  Plus other column flags like which country it's a holiday for, or whether it's a trading or settlement holiday for finance, or whatever.


Of course, logic works for weekends.  Is it just me who only sees weekends defined on this chart?



The ENTERPRISE way to approach this problem is to use a simple CRON routine that;



  • each day contacts TheDailyWTF

  • compares the entry to 'yesterday'

if it matches this must be a weekend or holiday!


 


VOILA!


 

Re: Time for a tblHoliday

2006-04-06 14:35 • by Martin

Surely, this should have been ...


<1975>
<January>
<1>Holiday</1>
<2>Work</2>
<3>Work</3>
...
</January>
...
</1975>
...


 


or even


\1975
  \January
    \1
      \Status.txt
    \2
      \Status.txt
...
Where Status.txt contains whether or not the day is a holiday.


 


(... hoping the forum does not screw the layout ...)

Re: Time for a tblHoliday

2006-04-06 14:36 • by lol
67356 in reply to 67354
ParkinT:
Anonymous:

Ken Nipper:
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........


I don't think "logic" is the way to go (not sure how you'd logically work out what the holidays would be, anyway -- plus, what happens when that "logic" changes?).  However, you could just put the dates in the table as dates, maybe with a nice little description for the holiday in a separate column.  Plus other column flags like which country it's a holiday for, or whether it's a trading or settlement holiday for finance, or whatever.


Of course, logic works for weekends.  Is it just me who only sees weekends defined on this chart?



The ENTERPRISE way to approach this problem is to use a simple CRON routine that;



  • each day contacts TheDailyWTF

  • compares the entry to 'yesterday'

if it matches this must be a weekend or holiday!


 


VOILA!


 



rofl that is fuckin funny shit.

Re: Time for a tblHoliday

2006-04-06 14:43 • by Maurits
This is actually a GOOD approach... caching calculations.

It should have been coupled with some kind of mechanism for generating rows for future years, though.

Re: Time for a tblHoliday

2006-04-06 14:56 • by tiro
67363 in reply to 67357
Caching calculations MIGHT be a good approach IF it turns out the calcuation is a bottleneck.  You can't figgure that out without profiling it.  Even then we're assuming that it takes less time to go out to the database and parse that mess instead of doing the calculation in the first place.

Either way, you can't know without profiling, and if it turns out that hitting the database is more efficient, well there's surely a better way of doing it than this bit of WTFery.

Re: Time for a tblHoliday

2006-04-06 14:57 • by wunderkind
67364 in reply to 67345
Anonymous:
The really funny thing is that it should be called "tblWeekends".


You're close, but not quite there.

It SHOULD be called "tblWeekdays"

Re: Time for a tblHoliday

2006-04-06 14:58 • by Jeff S
67365 in reply to 67363
Ok, I see "T" and "F", but what about "File not found?"

In all seriousness, I would love to see the rest of this "database."  or maybe not.

Great post Alex.  WTF ++ !

Re: Time for a tblHoliday

2006-04-06 15:01 • by Jeff S
67366 in reply to 67333
Ken Nipper:
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........


Holidays are *data* and should be stored in tables. 

However, as mentioned, it appears that he is simply declaring every weekend a "Holiday" so in that case logic would work, I suppose.

The guy who wrote this must be a fun guy to hang out with ... except for Monday-Friday or on any actual holiday that falls on a weekday, that is.

Re: Time for a tblHoliday

2006-04-06 15:04 • by Database Architect
If you want a real solution you should use the following table instead:

CREATE TABLE
    tblHoliday
(
    intYear   INT,
    bln0101   BIT,

    bln0102   BIT,


    bln0103   BIT,
    ...
    bln1231   BIT
)

Re: Time for a tblHoliday

2006-04-06 15:06 • by It's a Feature
67368 in reply to 67357

[:S]


Okay--just so I don't end up the guy who has to make sense out of the WTFs for holidays--


The right way to track holidays is to manually enter them into a table.  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?)  Some years a business will observe one holiday, while on others it will observe a different holiday.  Safest to always just put the list of observed holidays in a database.


And, for goodness sakes, just have a table with nothing but the actual date of the holiday:


 


Holiday Table (or whatever you want to call it)


Date  (a "Date" datatype, please)  | Description (optional column)


12/25/2006                                  | Christmas


 


 

Re: Time for a tblHoliday

2006-04-06 15:13 • by John Bigboote
67370 in reply to 67342
Mikademus:
That threw me off, why are the non-holidays marked "Y"?!




Because that will be your response. "YYYYYYYYYYYYes! I get to go to work!"



That's how awesome working for this company is.

Re: Time for a tblHoliday

2006-04-06 15:22 • by Richard Nixon
67373 in reply to 67354
ParkinT:
Why are there Braille markings on the Drive-up ATM?


1.    For blind people being driven to the ATM.
2.   Notice there is Braille on all ATMs, including those walk-up ones in the mall and at banks. Does it make sense to manufacture some ATMs with Braille and some without? No, of course not - make one mold, keep filling it.
3.   Americans with Disabilities act is probably another reason.

There, three reasons for you. Change your signature.

sincerely,
Richard Nixon

Re: Time for a tblHoliday

2006-04-06 15:23 • by HitScan
Man, I bet the leap year code for this mess is hell awesome.

Re: Time for a tblHoliday

2006-04-06 15:25 • by Ametheus
When did Christmas stop being a holiday?

Re: Time for a tblHoliday

2006-04-06 15:31 • by IQpierce
67376 in reply to 67375
Ametheus:
When did Christmas stop being a holiday?
Obvious! This company only gives you a holiday off if that Holiday falls on a weekend

Re: Time for a tblHoliday

2006-04-06 15:31 • by Kiwi
67377 in reply to 67336
Casiotone:
blnaryHoliday?

booleanary?


boolean array maybe

Re: Time for a tblHoliday

2006-04-06 15:37 • by Rick
67379 in reply to 67375
In the financial programming world, we all have 'holiday' tables. That part makes sense. Using a logic based solution would not be practical. Remember when Ronald Reagan died, the markets had a holiday added. Inserting one row into a 'holiday' table was easy, maintaining and releasing code is unfeasable.

Not using a datetime field for the holiday dates is what makes no sense.Using a database in such a way, that you can't possibly 'JOIN' to the required data is the WTF.

Re: Time for a tblHoliday

2006-04-06 15:39 • by Digitalbath
67380 in reply to 67346

jackass:
And it works great overseas.  All you have to do is create a new table and determine other countries holidays.


You mean that not everyone celebrates the 4th of July?  Weird. [:D]

Re: Time for a tblHoliday

2006-04-06 15:40 • by kipthegreat
67381 in reply to 67375
Ametheus:
When did Christmas stop being a holiday?


During the War On Christmas, obviously.  I guess Christmas lost.

Re: Time for a tblHoliday

2006-04-06 15:40 • by John Bigboote
67382 in reply to 67375
Ametheus:
When did Christmas stop being a holiday?




When the Christmas-hating liberal media got hold of the calendar industry.

Re: Time for a tblHoliday

2006-04-06 15:42 • by McDuck
scrooge@gold> mysql -uscrooge -pm0n3y
mysql> USE dbHoliday;
mysql> UPDATE tblHoliday SET binaryHoliday = INSERT(binaryHoliday, LENGTH(binaryHoliday)-6, 1, 'Y');

Re: Time for a tblHoliday

2006-04-06 15:45 • by HatTrick
67384 in reply to 67341
Anonymous:

Ken Nipper:
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........


I don't think "logic" is the way to go (not sure how you'd logically work out what the holidays would be, anyway -- plus, what happens when that "logic" changes?).  However, you could just put the dates in the table as dates, maybe with a nice little description for the holiday in a separate column.  Plus other column flags like which country it's a holiday for, or whether it's a trading or settlement holiday for finance, or whatever.


Of course, logic works for weekends.  Is it just me who only sees weekends defined on this chart?



What do you mean you can't use logic to calculate the holidays? There are rules for figuring out holidays and when they fall each year, they don't generally change. 


And yes I think you're right, I also do not see any holidays defined in this, only weekends.

Re: Time for a tblHoliday

2006-04-06 15:49 • by WTF Batman
67385 in reply to 67365
Jeff S:
Ok, I see "T" and "F", but what about "File not found?"

In all seriousness, I would love to see the rest of this "database."  or maybe not.

Great post Alex.  WTF ++ !


In the end, it was decided that 'F' would signify both False and Filenotfound, in the interest of saving precious bytes of memory. A random number would be generated, and then the mod(2) taken, to determine which value the current instance of 'F' implied.

Re: Time for a tblHoliday

2006-04-06 15:52 • by Bus Raker
67386 in reply to 67366

Jeff S:
Ken Nipper:
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........


Holidays are *data* and should be stored in tables. 

However, as mentioned, it appears that he is simply declaring every weekend a "Holiday" so in that case logic would work, I suppose.

The guy who wrote this must be a fun guy to hang out with ... except for Monday-Friday or on any actual holiday that falls on a weekday, that is.


 


Sorry every holiday has an exact calculation ... in Excel for instance they can represented like:


Memorial Day - Last Monday in May


=DATEVALUE("5/" & IF(WEEKDAY(DATEVALUE("5/31/" & intYear))>3, 35 -WEEKDAY(DATEVALUE("5/31/" & intYear)),28-WEEKDAY(DATEVALUE("5/1/" & intYear))) & "/" & intYear)


How you want to cache the results depends on your needs.


 


I sure wouldn't want to work for that company.  No holidays!


 

Re: Time for a tblHoliday

2006-04-06 15:52 • by WTF Batman
67387 in reply to 67385
WTF Batman:

In the end, it was decided that 'F' would signify both False and Filenotfound, in the interest of saving precious bytes of memory. A random number would be generated, and then the mod(2) taken, to determine which value the current instance of 'F' implied.


I should mention that the technical term for this logic is "WTF Overloading".

Re: Time for a tblHoliday

2006-04-06 15:58 • by nobody
This is actually GREAT! Finally a date system that can take leap-seconds into account on the scale of years :D

Re: Time for a tblHoliday

2006-04-06 16:00 • by stephen
67389 in reply to 67342
Mikademus:
That threw me off, why are the non-holidays marked "Y"?!

easy:
yes == yes, it is not a holiday
no == no, it is not not a holiday

Re: Time for a tblHoliday

2006-04-06 16:00 • by marvin_rabbit
67390 in reply to 67386
Bus Raker:

Jeff S:
Ken Nipper:
Hmmmm.......guess the original programmer thought it was more efficient to type Ys and Ns than to do say.........LOGIC...........


Holidays are *data* and should be stored in tables. 

However, as mentioned, it appears that he is simply declaring every weekend a "Holiday" so in that case logic would work, I suppose.

The guy who wrote this must be a fun guy to hang out with ... except for Monday-Friday or on any actual holiday that falls on a weekday, that is.


 


Sorry every holiday has an exact calculation ... in Excel for instance they can represented like:


Memorial Day - Last Monday in May


=DATEVALUE("5/" & IF(WEEKDAY(DATEVALUE("5/31/" & intYear))>3, 35 -WEEKDAY(DATEVALUE("5/31/" & intYear)),28-WEEKDAY(DATEVALUE("5/1/" & intYear))) & "/" & intYear)


Cool!  Can you show me the formula for Easter next?

Re: Time for a tblHoliday

2006-04-06 16:02 • by dmdietz
The real WTF here is that the original programmer didn't have the foresight to insert the days as XML entries into the database.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment