- 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
Of course they do, it returns a FILE_NOT_FOUND
Admin
And yet, in Soviet Russia, exceptions throw you.
Admin
That's why I use matlab.
Admin
Now for extra credit, you need to modify the function to be able to describe every possible date that could be supplied as a relative date, i.e. Today, Yesterday, Next Friday, Four weeks ago, One year, Three months, and seventeen days from now...
Admin
Admin
About the same as above, just readable :-p btw any could be a digit then you must parse the input
and a driver:
Admin
ok... here's my one-liner:
return DateFormat.getDateInstance().parse(checkMe).getTime()/(1000606024) == System.currentTimeMillis()/(1000606024)? "TODAY" : "NOT_TODAY";
This uses the fact that System.currentTimeMillis() returns milliseconds since January 1st 1970 (Midnight). Which tanks to rounding down with division I get the number of days since that date for the current time, and suggested time. The above code will work differently if you are using a non-US locale (which I could have explicitly set, but chances are you want the format to match the current locale).
BTW, if you ever see the date December 31st 1969, chances are someone stored the time of that event as -1 and forgot to check for it.
Admin
No you're wrong, it will work just fine. Unfortunately, String comparison is probably the best way to do this with the base java API. There is JodaTime, which attempts to rectify the many problems with Java Date handling.
You are right in thinking '?' is invalid. Has to be regexed out I guess.
I'm still surprised people think code like this is OK. Maybe you just have worse standards where you are.
Admin
Welllll... that would be true of any method whose output depends on the value of the current date.
It's just a fact of life we can't really guard against (or more to the point, not worth the added complexity to guard against)
My favourite thing about this WTF is that any delimiters are allowed. So '2007W03T29F' will still be a valid date :-P
Admin
Anyway, the real WTF is this site's software. The topic URL is : Maybe_NOT_0x5f_TODAY
That's right, space becomes underscore and underscore becomes "0x5f". I wonder what will happen if someone submites a story whose title includes "0x5f".
Admin
Well it sort of, almost makes sense from the perspective of calculation, if your are calculating the day of the year, then days_to_add => array ( 0 => 0, 1 => 31, 2 => 59, 3 => 90, 4 => 120, 5 => 151, 6 => 181, 7 => 212, 8 => 243, 9 => 273, 10 => 304, 11 => 335);
...with some logic thrown in for handling leap year situations if (month > 1 and ( !(year % 4) && (year % 100) || !(year % 400) ) ), of course.
I'm not sure that there really is any simple formulaic approach for getting the day of the year. It takes an array of some sort, unless you want to be really ugly and use a case statement or, worse yet, a twelve-step if-else [which would definitely be enough to drive one to drink and/or drugs].
Admin
Good point -- uh, maybe. It raise the question though. YTF are we asking the using to provide input in some goddamn geeky format?! That's what computers are for, ferfucksake!
Give them three combo boxes, one for months, one for days and one for four-digit years, and then lets do our end of the job with the data they enter.
Admin
This piece of code is from WebMethods (an integration platform). Although it could have been written a bit nicer it is quite common.
WebMethods doesn't know boolean etc. (it is java based, but uses a DOM like structure), everything is an object. To debug it is quite common to do most things as strings - hence the return value. It doesn't matter if you check for "true" or "today".
And no - there aren't users who can input something else - it's only integration (well, in most cases)
Admin
IData is an object commonly used when making interfaces with SAP. (BusinessConnector) And it's really annoying to work with. Also, about the comments about the date being returned as a string: it gets returned as a string by the cursor of the IData object, blame that class. You could blame the programmer for not parsing to a date though. But imho this is not a real wtf either, ...or I'm missing it. :)
Admin
Don't do that! Creating Gregorian Calendars is still very slow. Better reuse them if you can. :)
Admin
If you're going to use string-conversions any way, why not convert today's date to string and compare it to the input (ignoring the seperation characters of course)?
Takes out all your number conversion error problems or issues with the time or whatever.
Sorry to spoil the challenge...
Admin
String date = (IDataUtil.getString(cursor, "date")).trim(); DateFormat format = new SimpleDateFormat("dd.MM.yyyy"); String today = format.format(new Date()); if (today.equals(date)) return "TODAY"; return "NOT_TODAY";
wouldn't that make it easier?
Admin
Didn't read the comment on top, just remove those characters then and just use "ddMMyyyy" as pattern for the SDF then.
Admin
This is what i've found in a vendor-who's-name-shall-not-be-mentioned supplied PL/SQL program. Enjoy. I'm seriuosly NOT going to verify it actually works, i hope for god it does so i won't have to debug this.
Oh, and offcourse there is also a toGmtDiff function.
function fromgmtdiff(xDateTime DATE ,xTimezone char) return int as lDstStartMonthBegin DATE; lDstEndMonthBegin DATE; lDstStartMonthEnd DATE; lDstEndMonthEnd DATE; lDstStartDay INT; lLocStartDay INT; lDstStartWeek INT; lDstStartHour char(2); lDstStartMinute char(2); lDstStartSec char(2); lDstStartDate char(2); lLocStartDate char(2); lDstStartMonth char(2); lDstEndMonth char(2); lDstEndDay INT; lLocEndDay INT; lDstEndweek INT; lDstEndHour char(2); lDstEndMinute char(2); lDstEndSec char(2); lDstEndDate char(2); lLocEndDate char(2); lDSTOffset INT; dateOfFirstDayInstance INT; instanceNumber INT; dateInMonth INT; begin lDSTOffset:=0; /* 1753 is the earliest year supported by sql svr, dates beyond this cause date format errors */ if ((xDateTime is null)or(xTimezone is null)or(to_number(to_char(xDateTime ,'YYYY'))<1753)) then return 0; end if;
begin /get dst start and end date (upto month last date resolution) for the year of the given datetime/ select to_date(decode (td.dst_start_month ,1 ,31 ,2 ,p1.febDays ,3 ,31 ,4 ,30 ,5 ,31 ,6 ,30 ,7 ,31 ,8 ,31 ,9 ,30 ,10 ,31 ,11 ,30 ,12 ,31)||'-'||lpad(td.dst_start_month ,2 ,'0')||'-'||p1.digitYear ,'DD-MM-YYYY') ,to_date(decode (td.dst_end_month ,1 ,31 ,2 ,p1.febDays ,3 ,31 ,4 ,30 ,5 ,31 ,6 ,30 ,7 ,31 ,8 ,31 ,9 ,30 ,10 ,31 ,11 ,30 ,12 ,31)||'-'||lpad(td.dst_end_month ,2 ,'0')||'-'||p1.digitYear ,'DD-MM-YYYY') ,to_date(1||'-'||lpad(td.dst_start_month ,2 ,'0')||'-'||p1.digitYear ,'DD-MM-YYYY') ,to_date(1||'-'||lpad(td.dst_end_month ,2 ,'0')||'-'||p1.digitYear ,'DD-MM-YYYY') ,td.dst_start_month ,td.dst_start_date ,td.loc_start_date ,td.dst_start_week ,td.dst_start_day ,td.loc_start_day ,td.dst_start_hr ,td.dst_start_min ,td.dst_start_sec ,td.dst_end_month ,td.dst_end_date ,td.loc_end_date ,td.dst_end_week ,td.dst_end_day ,td.loc_end_day ,td.dst_end_hr ,td.dst_end_min ,td.dst_end_sec ,td.timediff into lDstStartMonthEnd ,lDstEndMonthEnd ,lDstStartMonthBegin ,lDstEndMonthBegin ,lDstStartMonth ,lDstStartDate ,lLocStartDate ,lDstStartWeek ,lDstStartDay ,lLocStartDay ,lDstStartHour ,lDstStartMinute ,lDstStartSec ,lDstEndMonth ,lDstEndDate ,lLocEndDate ,lDstEndWeek ,lDstEndDay ,lLocEndDay ,lDstEndHour ,lDstEndMinute ,lDstEndSec ,lDSTOffset from fgt_timezone_dst td ,(select decode(mod(to_number(p.digitYear) ,400) ,0 ,29 ,decode(mod(to_number(p.digitYear) ,100) ,0 ,28 ,decode(mod(to_number(p.digitYear) ,4) ,0 ,29 ,28)))febdays ,p.digitYear digitYear from (select to_char(xDateTime ,'YYYY')digitYear from dual)p)p1 where td.timezone_id=xTimezone; exception when no_data_found then return 0; end;
/create the start and end dates for the DST range/ if (lDstStartDate is not null and lDstEndDate is not null) then /* the local time with timediff results in GMT time being on the earlier day */ if (lLocStartDate<>lDstStartDate) then if (lLocStartDate=1) then /if local date is first of month then GMT date will be on last date of previous month/ lDstStartMonthBegin:=to_date(to_char(lDstStartMonthBegin-1 ,'DD-MM-YYYY')||' '||lDstStartHour||':'||lDstStartMinute||':'||lDstStartSec ,'DD-MM-YYYY HH24:MI:SS'); else /GMT date will be date of previous to local date in same month/ lDstStartMonthBegin:=to_date((lLocStartDate-1)||'-'||to_char(lDstStartMonthBegin ,'MM-YYYY')||' '||lDstStartHour||':'||lDstStartMinute||':'||lDstStartSec ,'DD-MM-YYYY HH24:MI:SS'); end if;
else /* Calcluate the start date */ instanceNumber:=lDstStartWeek; if (to_char(lDstStartMonthBegin ,'D')>lLocStartDay) then dateOfFirstDayInstance:=abs(to_char(lDstStartMonthBegin ,'D')-(7+lLocStartDay))+1; elsif(to_char(lDstStartMonthBegin ,'D')<=lLocStartDay) then dateOfFirstDayInstance:=abs(to_char(lDstStartMonthBegin ,'D')-lLocStartDay)+1; end if;
end if;
/check if date is in range and set the offset value/ if (lDstStartMonth-lDstEndMonth<0) then /if the range is in the same year/ if ((xDateTime>=lDstStartMonthBegin)and(xDateTime<=lDstEndMonthBegin)) then return lDSTOffset; else return 0; end if;
elsif(lDstStartMonth-lDstEndMonth>0) then /if the range is a year crossover/ if ((xDateTime>=lDstStartMonthBegin)or(xDateTime<=lDstEndMonthBegin)) then return lDSTOffset; else return 0; end if;
end if;
return lDSTOffset; end FromGMTDiff;
Admin
OMG...
Captcha: riaa Indeed, that was about the second thing that came to mind
Admin
God bless Sun and IBM for Date and Calendar! Never fix APIs!!!!
Admin
In my opinion this is not so terribly wrong. When you compare two GregorianCalendar instances in Java (I suppose this being java code), not only the date, but also the time is compared. If there is no Time set explicitely, the system's current time is taken.
So if you concider the "reference date" beging created at program start (and updated, if date changes), you can assume that it will never be equal to the current date, when the new date is instanciated later.
Admin
Admin
Read the API ffs ! These are constants used for rolling the date up and down, not the values.
If it aint broken, fix it until it is, literally.
Admin
Admin
That is the funniest response EV-ER. :D
Admin
Actually, I think you've got the race condition backwards. After all, the date IS equal to TODAY at the time the function returns, which may be more interesting. However, if the current time is grabbed too early then it will moments later say that it's NOT_TODAY, even though it is.
Regardless, it's unlikely to hurt anything.
Admin
Admin
Today or not today, that is the question...
Admin
I think it's missin 13 as MONTH_NOT_FOUND
Admin
I allways get my 13th month in May, but that's another story
Admin
Admin
Admin
prednisone for dogs: http://prednisone1st.store/# prednisone 30 mg