Sugar.DateTime constructor bug

When initializing a DateTime and printing it results in the wrong time being printed:

You can reproduce it by executing the following code:

print("Time = \(Sugar.DateTime(2000, 2, 14, 0, 0, 0).ToString())")

The output is:
Time = 14/02/2000 12:00:00

And the expected output is:
Time = 14/02/2000 00:00:00

How come 0 is seen as 12? When passing 1 the hour is displayed correctly

Could this simply be a 12 vs 24h display issue? Where 12:00 am is printed as 0:00? What locale are you on, and what platform does the shape with — .NET, Cocoa or Java?

Well the issue is not that 12.00 is printed as 0:00. It’s the other way around. hour 0 is printed as 12:00 and hour 1 is printed as 01:00. Locale is GMT + 1 and this issue is on Android.

But it’s probably just something in the ToString method causing this behaviour. Since hours:

  • 0
  • 12
  • 24

are all printed as 12:00

and hour 23 is printed as 11:00 instead of 23:00.

So I guess the easiest way to work around this is using the getHour() method in a own Formatter since this results in the following:

  • 0 results in 0
  • 24 results in 0
  • 12 results in 12

Right. That’s just how the 12-h time system prints time?