os.time returning nil for specific date on Android device

I’m having trouble with os.time on my actual Android phone. On the simulator, the following lines all work just fine, but for some reason, this specific date is returning nil on my old HTC Droid Incredible (ADR6300) Android phone.

Code:

[lua]

print("Time 1: ", os.time({year=2015, month=3, day=7, hour=2, min=5, sec=42}))
print("Time 2: ", os.time({year=2015, month=3, day=8, hour=2, min=5, sec=42}))
print("Time 3: ", os.time({year=2015, month=3, day=9, hour=2, min=5, sec=42}))
[/lua]

Output from adb logcat:

[lua]

I/Corona  (16936): Time 1:     1425722742
I/Corona  (16936): Time 2:     nil
I/Corona  (16936): Time 3:     1425891942

[/lua]

As you can see, the only thing I change between the 3 is the day, and March 8, 2015 should definitely be a valid day. Any ideas what may be wrong here? I’ve tried restarting the phone and re-installing several times. The phone is on the very old 2.3.4 gingerbread OS, so maybe it’s just an old bug that’s since been fixed (I don’t have an easy way of testing that myself). I’ve tried building with Corona 2014.2511 (public release) and the latest daily build from today, 2015.2589. Thanks for any ideas!

It happens on my Google Nexus 7 running 5.1.  I’ll let Engineering know.

Bug report #39818

Rob

Thanks, Rob!

This is a bug in the Android library due to the isdst value not being set correctly.    This works:

print("Time 2: ", os.time({year=2015, month=3, day=8, hour=2, min=5, sec=42, isdst=false}))

Since it’s an Android bug, we can’t do much about it, but by providing a value for isdst (Is Daylight Savings Time), you can work around it.

Rob

Oh wow, it never dawned on me that March 8 was when DST kicked in this year. I’m pretty sure that workaround will be fine for my case. Thanks for the info! On a side note, I take it we don’t have a good way to determine if the phone thinks it’s on DST, or even what time zone it’s in? I’m guessing you can make some assumptions based on getting the current time’s tzoffset, but that’s all I could think of.

You should be able to take the current time with os.time() and use os.date() to set a table of entries and hopefully isdst will be set for you.  Then you can use that when creating other dates.

Rob

It happens on my Google Nexus 7 running 5.1.  I’ll let Engineering know.

Bug report #39818

Rob

Thanks, Rob!

This is a bug in the Android library due to the isdst value not being set correctly.    This works:

print("Time 2: ", os.time({year=2015, month=3, day=8, hour=2, min=5, sec=42, isdst=false}))

Since it’s an Android bug, we can’t do much about it, but by providing a value for isdst (Is Daylight Savings Time), you can work around it.

Rob

Oh wow, it never dawned on me that March 8 was when DST kicked in this year. I’m pretty sure that workaround will be fine for my case. Thanks for the info! On a side note, I take it we don’t have a good way to determine if the phone thinks it’s on DST, or even what time zone it’s in? I’m guessing you can make some assumptions based on getting the current time’s tzoffset, but that’s all I could think of.

You should be able to take the current time with os.time() and use os.date() to set a table of entries and hopefully isdst will be set for you.  Then you can use that when creating other dates.

Rob