5
$\begingroup$

So I used TimeZoneConvert to get the time in GMT:

TimeZoneConvert[Now,"GMT"]

It outputs a date object that says Tuesday 14 March 2017 02:45:08 GMT.

But when I then try:

DayName @ TimeZoneConvert[Now, "GMT"]

I get Monday, even though the date object is a Tuesday. What's going on here?

commands

| improve this question | | | | |
$\endgroup$
6
$\begingroup$

Bug Confirmed by Wolfram Research

My time zone is GMT+8, which is used in this answer.

I can only explain how you get the incorrect answer.

First we need to read the definitions to trace the evaluation. The powerful tool I used is GeneralUtilities`PrintDefinitions. I will just show the main steps.

First store that converted date object in t, t = TimeZoneConvert[Now,"GMT"].

Check what's inside

t//InputForm
DateObject[{2017, 3, 14}, 
 TimeObject[{5, 58, 23.634473}, 
  TimeZone -> "GMT"], 
 TimeZone -> "GMT"]

From the definitions of DayName,

DataPaclets`CalendarDataDump`iDayName[t]
(*Monday*)

Then,

DataPaclets`CalendarDataDump`doDayName[t]
(*Monday*)

Then,

DataPaclets`CalendarDataDump`ToInternalDate[{"Gregorian", t}, DayName]
(*{"Gregorian", 2017, 3, 13, 21, 58, 23.6345}*)

Here we noticed that this function AGAIN subtracted 8 hours from the date, which is incorrect. Its code mainly contains two parts, the first is roughly

System`DateObjectDump`$tempDate = t;
System`DateObjectDump`correctTimeZoneOffset[
 System`DateObjectDump`iObjectTimeZone[t]]
(*I added the first line to make the code works, otherwise it returns $Failed, I got the value of $tempdate from tracing*)

This returns 0, which is the time zone for this date. The return value of this function is

DateList[Join[PadRight[date, 3, 1], First @ time], TimeZone -> tz]

which is

DateList[Join[PadRight[{2017, 3, 14}, 3, 1], 
  First @TimeObject[{5, 58, 23.634473}, TimeZone -> "GMT"]], 
 TimeZone -> 0]

in our case. Unfortunately, from the docs of DateList

DateList[TimeZone->z] gives the date and time inferred for time zone z by assuming that your computer is set for the time zone specified by $TimeZone. »

It is assuming the input, {2017, 3, 14, 5, 58, 23.6345} is the local time, and converts it to TimeZone -> 0, so then another 8 hours is subtracted from it, finally we get

{2017, 3, 13, 21, 58, 23.6345}
| improve this answer | | | | |
$\endgroup$
  • 3
    $\begingroup$ @numbermaniac of course. I have filled a support form. The case number is 3859858 $\endgroup$ – happy fish Mar 14 '17 at 8:15
  • $\begingroup$ Awesome, thanks! $\endgroup$ – numbermaniac Mar 14 '17 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.