- 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
addHours(-1) I laughed out loud at that.
Admin
Oh, and frist
Admin
I don't see any need to alter the hours.
Plus I think you can use utcNow.format("Ymdh") ??
Admin
Admin
Source control is optional? Sounds like the perfect opportunity for an misplaced "return true" to debug on Tuesday.
Or they could check what files the cameras were actually producing.
Admin
Doesn't the second version look for the file to be written at 11pm today the first hour after midnight?
Admin
To my non-java-trained eyes, this looks like a reasonable API call. A very ugly API for sure (who wouldn't prefer Date("now -1h").format("YYYYMMDDHH") ?), but if you're going to implement an addhours() method, why forbid negative arguments ? You don't want to do the maths yourself, in order to handle DST correctly.
Admin
Admin
DateTime.Now.ToFileTimeUtc() surely?
Admin
there is no DST in UTC
also a format call would be infinitely better than that horrendous setup
Admin
This should do it:
Admin
My guess would be he needs to check for the archive file after its closed, the camera software probably closes and renames its archive files every hour or something. So if he runs at 23:00 he probably needs to be looking for a file named for the 22:00 hour. Otherwise it might be a full hour before the monitor discovers the video camera's have failed.
The TWTF is the anti-pattern of naming files with dates. The filesystem already keeps track of cdate, mdate, and often atime. Seriously in a situation like better just to give the files consecutive numbers not only do you avoid these types a problems; you get filenames that will always sort neatly with other tools. If you are really really worried about losing the filesystem metadata somehow, then just append the files name and data to CSV file or database somewhere at create time.
Admin
Why exactly is that an anti-pattern, and not just your opinion on the matter?
There is no technical reason why filenames should not contain datetime info, assuming you use a format which allows alphanumeric sorting.
In addition, if you have a file of "video footage for the security camera in the lobby between 6 and 7 today" then the location of the footage and the datetime it was taken are the actual contents of the file... in this case the datetime isn't meta-data, it's integral to accurately describe the content of the file, and is therefore appropriate to include that info in the title of the file.
To not include such data is to produce a bunch of inconveniently named files, just so that you can feel smug about sticking to some weird (and spurious) file naming principle.
Admin
nothing to do with the story, but why does the first page of comments have a "prev" in the lower left? it is not linked to anything.
Admin
Standard behaviour out of the box is some sort of gallery view - a nice thumbnail, name underneath.
cdate, mdate, atime? Available, you just have to right click on the file and select "Properties", after which a nice window opens up (which you will then have to close again).
Care to do that for the 168 files the cover the last seven days of a camera? Thought so.
A filename should be descriptive and the YYYYMMDDHH pattern is descriptive.
Yes, you can set windows explorer to "list view" modus. But if you look closely, what is displayed is the mdate, not the cdate. Any change to the file and you are lost.
And you gain what exactly against the YYYYMMDDHH? Nothing.Apart from the fact that for each generated file you have to find out the highest filenumber used, and then increment that by 1.
Oh, and what if you move all the files from the avi directory to an archive folder on some other drive? How will you then determine the next filename? If you start with 1.avi again, you will get ambiguous file names.
There are two reasons why the YYYYMMDDHH pattern is in widespread use: first, if you stick to the pattern, the filenames are unique for all eternity (well, at least until the year 9999). Second, YYYYMMDDHH is a number. A number that makes comparisons rather easy. If all you ever need is "is a greater/less than b" YYYYMMDDHH is for you.
You were advocating numbers for the filenames. Well, that's what you've got with the pattern.
Admin
So you';ve got a bunch of cameras each dumping 1hrs worth of captured video to a storage subsystem, and you want to trust the filesystem as a reliable moderator of what information that file contains?
Sure, that sounds robust to me.
(and while we're here, I'm pretty sure TRWTF is that you can't spell TRWTF...)
Admin
Admin
utcNow.AddHours(-1) is correct. However he should be subtracting one from the whole date object, and formatting the output from that.
Subtracting one from the hour at midnight will result in the 23rd hour from the previous day, but since he is only ripping out the HH part the whole date rollover gets lost.
Admin
But that's pretty lame in its own right...
(But not as lame as the stuff on The Lame List.)
Admin
Fair enough, I don't know much java nor c# (and don't mind keeping it that way).
So... I still don't see where the bug is. I'd have implemented things differently for sure, but how does that code fail ?
Admin
But what he wrote was "The TWTF". So ... the True WTF perhaps? Do we have a believer in our midst?
The THE WTF? It's so definite it needs two definite articles?
Any other options? ;)
Admin
If it actually subtracted 1 hour from the date it'd be fine.
But what it does is get the current year, month, and hour separately, then concatenate them. So instead of looking for, say, 2014020323.avi, it looks for 20140204-01.avi.
EDIT: sorry, should add - the second version would produce 2014020423.avi for the above example. Closer, but still wrong ;)
Admin
there is no handling for hour roll-over -> 0 becomes 23 on the same day instead of the previous day
Admin
Well... I give you:
Video_98 Video_99 Video_100 Video_101
(and if you tell me "You just have to prefix the zeroes of course". The I tell you "As soon as you tell me the maximum number of digigs... Of Course")
In short: IF you're doing time specific stuff YYYYMMDDHH is way better!
Admin
It will always look for the files generated one hour removed.
Say the cameras save on the full hour, and that the camera is disabled on February 3rd, somewhere between 22:00 and 22:59. Say, at 22:10.
On February 3rd at 23:05 the monitor will test for 2014020322.avi and will find it.
On February 4th at 00:05 the monitor will test for 2014020323.avi and will not find it. An alarm goes of.
The point is, the alarm is going off one hour late. For security systems, such an error can be close to unacceptable.
Admin
Camera: 2014020300.avi Ted: 20140203-1.avi
The file 20140203-1.avi does not exist, so the monitor assumes camera malfunction and falsely raises an alarm.
Admin
lol, saw exactly the same problem in one of our (ops-developed) server management tools (though nothing critical, just prefilling some date)
DateTime.Now.addHours(-[2]).Hour DateTime.Now.Day DateTime.Now.Month DateTime.Now.Year
close, but no cigar ;) on the other hand, that thing is only supposed to be on test anyway and nobody is testing stuff at 22:00 anyway.
Admin
The technical WTF? As opposed to the management WTF or the inappropriate-personal-behaviour WTF?
Admin
The right way (TM) is to create a look-up table of pre-calculated file names:
Because then you can store the ID as the seconds since the last epoch as the lookup key! Zing!
Admin
TRWTF is Eric a) not using Ted's cellphone and b) not using the elevator. Although, to be fair, it doesn't state on which floor the programming is being done -- if it's floor 14 then Eric's feat of athleticism is possibly borderline excusable.
Admin
I'm not sure what language this is, but if utcNow is a function call, and not just a variable, then you have a race condition: if part of the expression executes a microsecond before midnight, and part a microsecond after, then you could be up to a YEAR off, even without needing to subtract that hour.
Admin
If this story takes place at midnight in New York, isn't UtcNow going to return a timestamp around 5am?
Unless they mean New York, England. http://en.wikipedia.org/wiki/New_York,_Tyne_and_Wear
Admin
Admin
But still not enterprisey enough. Where's the xml and the regex?
Admin
Oops....
Ummmm....
I did say "if this story takes place in New York."
Admin
Admin
The story says the that "the ball had just dropped"; I don't know where in the world balls drop for New Year outside of New York, New York. (Not aware of any dropping at midnight in anywhere that has a time zone aligning with UTC at New Year.)
Admin
I suppose it might be the Teleological WTF. (WTF By Design?)
Admin
The GlassHouse application throwing an exception of type EStone.
... which fails because EarlyBird() only catches EWorm.
Forgetting to free() the Lunch pointer.
Closing the Friends file without closing the Enemies file first.
Misusing the /home directory.
Admin
Camera: 2014020300.avi Ted (fixed): 2014020323.avi
2014020323.avi does (not yet) exist, so again Ted's monitor raises a false alarm.
Agreed. But it's ok since it supports the wtf in a nice way (quick buggy hack, bugfix buggy as well). You can excuse Ted for not thinking too clearly during a party; without the party, Ted's fix would represent a nice head->desk moment.Admin
Heh, I found something like that in some internal code I inherited a while back - only it was in a filter on the Month, so nobody had noticed it until December: take the current month, turn it into an int, add one, turn it back into a month. Brillant.
Admin
Admin
I hate those "language inside a language" types of APIs. The meaning of "utcNow.Hour.AddHour(-1)" is pretty freaking obvious[1] and easy to remember.
With "Date('now -1h'), you have a new language that you need to learn. It may be a simple language, but it's still new, and it opens up new possibilities for parsing bugs or surprising behavior (does "now -1:30" work?). Plus that language isn't type checked or even compiled. If it's bombs, it does so at run time. If you – god forbid – mix user-supplied data into that format string, does it open up new new security vulnerabilities?
Keep it simple, stupid.
Admin
UTC-1? Seriously?!
Admin
My good friend Rory Jack Thompson once told me always manipulate your date before chopping into pieces...
We had different interpretations of course but still sage advice...
Admin
Obviously it's "The TIME WTF", duh
Admin
I'm thinking the answer is simper than that. If you're saving a file at 11pm it's the video from 10pm to 11pm (or 10:59:59). Granted they could just remember that the 2014020323 file is in fact for 22-23, but it makes slightly more sense to name it with the start time.
Admin
"Whatever you do, don't feed it after midnight" I've heard that before somewhere...
Admin
You're assuming the hour in the filename is the save time of the recording. If it's the start time of the recording, the -1 logic is correct i.e. 2014020322.avi is the file that starts at 22:00 on 03/02/2014*
*waits for inevitable argument about endianism of dates...
Admin
Just posting to troll that TRWTF is our insane set of units for time - years, days, hours, .. all those nondecimal (or non hexadecimal, alla same) units.
Or maybe TRRWTF is that our planet refuses to complete a revolution in an integral number of solar-oriented rotations.