Group Abstract Group Abstract

Message Boards Message Boards

0
|
389 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Strange behaviour of DateString when TimeZone is set to DateObject under WolframCloud

Posted 1 month ago

I noticed strance behaviour under WolframCloud when using DateString with DateObject having TimeZone set.

I run same DateString operation for three different DateObject instances where first two of them produces expected result i.e. current date and time in Finnish. However the third one where I have explicitly set TimeZone to correct one, I am getting totally wrong result for the time:

DateString[#, <|"Elements"->"LocaleDateTimeShort", "Language"->"Finnish"|>]& /@
{
  DateObject[],
  DateObject[TimeZone->None],
  DateObject[TimeZone->"Europe/Helsinki"]
}

Output:

{16.8.2025 klo 13.29.48,16.8.2025 klo 13.29.48,16.8.2025 klo 21.29.48}

As seen in the output the last member have time totally incorrect 21.29.48 when correct time would be 13.29.48 so that would be several hour off. But this happens only in WolframCloud and not in the desktop version.

I am not sure if this is a bug or if I am just not understand the meaning of TimeZone correctly in this context.

POSTED BY: Teemu Ahola
5 Replies
Posted 27 days ago

I don't know how/whether the WolframCloud determines your local timezone, but my desktop version always has "knowledge" of my local timezone (there are things I can do to override that knowledge, but that's not really relevant). The dates presented to me, unless I specify a timezone, are always presented as the time in my local timezone. So, notice that in your case, the function that you're mapping has no timezone specified. So, the results are shown to you as if they were in your local timezone. The third date object was a time specified with the local offset of Helsinki, which would be several hours different from wherever you are, apparently. So, the date presented to you, which again is local to you, has been shifted to account for this.

POSTED BY: Eric Rimbey

What is your current $TimeZone value? The results you're getting make it seem like there's a difference between your local time and Finnish time. A few things I'd verify before saying for sure what's going on:

In[72]:= {$TimeZone, DateObject[], DateObject[TimeZone -> None], 
 DateObject[TimeZone -> "Europe/Helsinki"]}

Out[72]= {-5., 
 DateObject[{2025, 8, 18, 8, 30, 55.686924}, "Instant", "Gregorian", -5.], 
 DateObject[{2025, 8, 18, 8, 30, 55.686983}, "Instant", "Gregorian", None], 
 DateObject[{2025, 8, 18, 16, 30, 55.687137}, "Instant", "Gregorian", "Europe/Helsinki"]

}

so for me, with a GMT-5 timezone, the dates generated without a time zone specification give me local time (currently 8:30 am) but when the target time zone is Helsiki it correctly shows that it's 4:30 pm in Finnland currently.

POSTED BY: Nick Lariviere
Posted 27 days ago

It seems that just by looking DateObject itself things are correct in Wolfram Cloud:

{$TimeZone, DateObject[], DateObject[TimeZone -> None], 
DateObject[TimeZone -> "Europe/Helsinki"]}

{3.,
 DateObject[{2025, 8, 18, 20, 52, 41.576097}, "Instant", 
  "Gregorian", 3.], 
 DateObject[{2025, 8, 18, 20, 52, 41.576202}, "Instant", "Gregorian", 
  None],
 DateObject[{2025, 8, 18, 20, 52, 42.353321}, "Instant", 
  "Gregorian", "Europe/Helsinki"]} 

but I I pass DateObject[] and DateObject[TimeZone->"Europe/Helsinki"] to DateString something goes wrong:

DateString[#,<|"Elements"->"LocaleDateTimeShort"|>]& /@ {
  DateObject[],
  DateObject[TimeZone -> "Europe/Helsinki"]
}

{"Aug 18, 2025, 9:02:36 PM", "Aug 19, 2025, 5:02:36 AM"}  

Even the day is wrong for the DateObject with TimeZone. There is no such error in desktop version. If I define Language and remove Elements specifications:

DateString[#, <|"Language"->"Finnish"|>]& /@ {
  DateObject[],
  DateObject[TimeZone -> "Europe/Helsinki"]
}  

{"18.8.2025 9:07 ip.", "19.8.2025 5:07 ap."} 

So time is again wrong.

However if I remove Elements and Language specifications, thinks starts to look OK:

DateString[#] & /@ {
  DateObject[],
  DateObject[TimeZone -> "Europe/Helsinki"]
}
{Mon 18 Aug 2025 21:06:19, 18.8.2025 9:06 pm} 

So looks like that Element->"LocaleDateTimeShort" and Language specifications somehow break the textual presentation of DateObject.

POSTED BY: Teemu Ahola
POSTED BY: Nick Lariviere

In the meantime, you can force the correct result by adding an explicit TimeZone -> "Europe/Helsinki" option value to the DateString call itself:

In[102]:= $TimeZone = 3;
DateString[#, <|"Elements" -> "LocaleDateTimeShort"|>, 
   TimeZone -> $TimeZone] & /@ {DateObject[], 
  DateObject[TimeZone -> "Europe/Helsinki"]}

Out[102]= {"Aug 18, 2025, 10:02:23 PM", "Aug 18, 2025, 10:02:23 PM"}
POSTED BY: Nick Lariviere
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard