r/shittyprogramming • • Aug 14 '14

getTomorrowsDate() (xPost from /r/ProgrammingHumor)

Post image
695 Upvotes

24 comments sorted by

4

u/Intrexa Aug 15 '14

I have a similar problem that I am working on, that I can't quite get this solution to work for. I need to get yesterdays date, anyone know how I can transform this solution to do that?

34

u/ActuallyRuben Aug 15 '14

Just replace

sleep(1000*60*60*24)

With

sleep(-1000*60*60*24)

95

u/SwissPatriotRG Aug 15 '14

The only problem I see is the method is named incorrectly.

getTodaysDateTomorrow() would pass my code review.

29

u/MetaLemons Aug 15 '14

What is today, but yesterday's tomorrow?

0

u/[deleted] Aug 15 '14

[deleted]

4

u/PublicSealedClass Aug 15 '14

But when will then be now?

4

u/mebob85 Aug 20 '14

Soon.

P.S. I hope this is the reference I think it is

2

u/PublicSealedClass Aug 20 '14

It is indeed! Can't believe that went 4 days without a response/"I understood that reference" macro.

2

u/NazzerDawk Aug 29 '14

Yesterday... Love was such an easy gaaaame to plaaaayy....

43

u/daV1980 Aug 15 '14

Even funnier--it doesn't always work.

If it's after 11 PM and the next day is "spring forward," there are only 23 hours in the day and the code will return the wrong date.

75

u/Msskue Aug 15 '14

Given the caliber of the code I'm shocked the author didn't take this into consideration.

6

u/golergka Jan 17 '15

He didn't even check for leap seconds!

13

u/SwissPatriotRG Aug 15 '14

int tomorrowMilliseconds = (GetCurrentDate().addDays(1) -getCurrentDate()).toMilliseconds());

sleep(tomorrowMilliseconds);

getCurrentDate();

Fixed that bug booyah!

82

u/petermlm Aug 14 '14

doesn't even return

25

u/irrotation Aug 15 '14

Probably done in language with optional return.

0

u/[deleted] Aug 16 '14

[deleted]

2

u/irrotation Aug 16 '14

It depends. If the code is compiled then there will be an error if the return is wrong. This is the case in Scala, for example.

1

u/[deleted] Sep 20 '14

Uhh... I'm currently working on a project using a scala back-end and js on the front. I've lost count on the times I'm stuck wondering why nothing is happening in my js functions because I omitted return...

20

u/Matty_R Aug 15 '14 edited Aug 15 '14

Oh god.. I laughed far too much at this. Or not enough? I don't even know anymore.

Imgur It was bugging me so I adding return.

16

u/jen1980 Aug 15 '14

That could be made more efficient by using sleep(86400);

65

u/myhf Aug 15 '14

A sufficiently smart compiler (TM) can fill that in. The declarative, multiplication-based method is more maintainable in case the number of seconds per day changes later.

25

u/pointychimp Aug 15 '14

multiplication was the reason I dropped out in 4th grade. I wouldn't want to put my computer through that too.

7

u/ryeguy146 Aug 15 '14

At least he provided a comment, 'caus I'll be damned if I knew what it was supposed to do without that.

5

u/popidiots Aug 29 '14

I'm going through the whole top-rated for this sub and this is my favourite so far

9

u/Meshiest Aug 15 '14

Well, if it returned a value, it wouldn't be wrong.

5

u/SmBe19 Aug 15 '14

Well, there are languages where you don't have to write return explicitly for a function to return something... Then the last processed expression will be the return value (Ruby for example).

0

u/[deleted] Aug 15 '14

[deleted]

3

u/Meshiest Aug 15 '14
def getTomorrowsDate
    sleep(1000*60*60*24)
    Time.now.to_i
end

1

u/[deleted] Aug 15 '14

Well, that's great, unless his process receives a signal that interrupts the sleep call.

0

u/[deleted] Aug 15 '14

[deleted]

2

u/[deleted] Aug 15 '14

Or more importantly, transitions from summer to winter time-zones as pointed out elsewhere in the comments.