• frist (unregistered)

    First?

  • A_L (unregistered)

    Seconds!

  • JimTonic (unregistered)

    Thrids? I love dates, but only when they're fresh.

  • dgushurst (unregistered)

    These dates are beyond fresh. Putrid and rancid are two words that come to mind.

  • Guest (unregistered)

    It looks like it is figuring out the number of days since the beginning of the month. There just might be a simpler way?

  • Jeremy (unregistered)

    It's figuring whether the PaymentDate - October 5, 2016 - is more than 10 days from DateTme.Now. In PowerShell you'd do this

    if ( ([DateTime]::new(2016,10,05) - [DateTime]::Now).Days -gt 10) { #Do true stuff here } else { #do False stuff here }

    In C# it would be almost identical.

  • Rick (unregistered)

    If I understand this correctly, it only works if the default date format of the current locale is in the form "day.month.year TimePortion", and its purpose is to find the number of days between two dates. Any locale that doesn't have "day" in the first position, that doesn't use "." as a date separator, or that doesn't use a space to separate the date and time portions will fail.

    I've seen code like this submitted to a first-year Comp Sci course I was TA'ing.

  • Some Programmer (unregistered)

    Fixed the code...

    return (Convert.ToDateTime("10/05/2016") - DateTime.Today).Days > 10;

  • Peter Pedantic (unregistered) in reply to Some Programmer

    The "Fixed code" does not do the same thing as the original code. For all you know, the return value is ignored by the caller and the console output is being parsed instead ... ;)

  • Phuul (unregistered) in reply to Rick

    You don't understand the code correctly.

    The purpose is to see if the payment date is more than 10 days from the current date. The date separator doesn't matter. When it splits on a period it is dropping the remainder of the P(payment date) - C(current date) to get the integer value.

  • Sabre (unregistered)

    For bonus WTF points, the Convert.ToInt32() throws a FormatException if run on 10/05/2016, since the "d." part of the TimeSpan.ToString() default format string is optional (so the output will be "00:00:00" which doesn't parse).

  • Herby (unregistered)

    Today's lesson:

    Time and date problems are HARD. Usually your platform of choice has functions that are well tested and do many of the functions you need.

    USE THEM. Do not, repeat DO NOT attempt to make your own. They will fail in strange ways.

    If your platform doesn't have said time and date functions, GET ANOTHER PLATFORM!

  • Yazeran (unregistered)

    Oh, and as mentioned in the html comments, why the hard coded day. What's so special about May 10'th 2016???

    The mind boggles.

    Yazeran

  • (nodebb) in reply to Jeremy

    No in c# it would be thus:

    if(MyDate.Subtract(DateTime.Now.Date).Days > 10)

  • NotBugItsFeature (unregistered)

    The hard coded date threw me off. Then I saw him convert to a string. I thought, "Oh, he's stripping the time... on a hard coded timeless value... okay... at least he does it for the DateTime.Now later on. Maybe it's an anti pattern." It's the wrong way to do it, but I've seen that before. Then, when he converts back to a DateTime, he calls the Date property! That's the correct way to strip the time! How the.... why the....

    The rest is pure madness as far as I am concerned. I don't care if it actually does anything useful. Madness.

  • NotBugItsFeature (unregistered)

    Also, are we sure he's trying to get the day? I mean, sure, the date in the string looks American, then he splits with a period. Dude might be from Kazakhstan for all we know.

  • löchlein deluxe (unregistered) in reply to Yazeran

    "All the example datasets they gave me had that date, how should I know it's not always the same, I know nothing about the problem domain. I'm just trying to adjust for timezones and DST."

  • Ex-lurker (unregistered) in reply to NotBugItsFeature

    Seems like there's a lot of confusion in this thread. For the record, that split('.') DOES NOT have anything to do with the date objects.

    What this idiot did, essentially, was: grab the current date and a hardcoded date, juggle them with a lot of unnecessary type conversions, strip away the time with that split(' ') , subtract one from the other, convert the result to string and use that split('.') to ignore the decimal part (because that's totally the correct way to take the integer part of a number, not using those silly round() or floor() math functions) and see if there were more than 10 days between both dates.

    All that cruft just to check if DateA - DateB > 10 days. That's how moronic this code is.

    If that wasn't bad enough I see dozens of ways this code can fail spectacularly. Changing from USA to SI date formats or the other way around are obvious but in several countries the decimal separator isn't a period either. Whoever wrote this code is either severely mentally challenged or a coder so awful that they shouldn't be allowed to touch a VCR, let alone a computer's keyboard.

  • mz6lu (unregistered)

    TRWTF is the date format amiright?

  • Ugh (unregistered)

    TRWTF is the comment spam.

  • Super Genius (unregistered) in reply to Rick

    If I understand this correctly, it only works if the default date format of the current locale is in the form "day.month.year TimePortion"

    And good. Anyone who uses other date format than dd.mm.YYYY and 24h time system or uses imperial units is obviously an insane moron.

Leave a comment on “Robotic Implementation”

Log In or post as a guest

Replying to comment #:

« Return to Article