Message Boards Message Boards

0
|
2259 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Adding a time quantity to a TimeObject

Posted 3 years ago

In a calculation involving TimeObjects I noted that the addition of a time quantity to a TimeObject behaves differently depending on whether the TimeZone of the TimeObject is equal to the current $TimeZone or not.

For example the addition of 1 hour to a TimeObject with no explicit TimeZone

TimeObject[{12, 0, 0}] + Quantity[1, "Hours"]

yields the expected result (given in InputForm):

TimeObject[{13, 0, 0}, "Instant", None]

Similarly, when the TimeZone is set to the local TimeZone (in my case $TimeZone is 1.):

TimeObject[{12, 0, 0}, TimeZone -> $TimeZone] + Quantity[1, "Hours"]

yields (again in InputForm):

TimeObject[{13, 0, 0}, "Instant", 1.]

However, if a TimeObject in a TimeZone different from the local TimeZone (here: Tokyo) is used

TimeObject[{12, 0, 0},TimeZone -> LocalTimeZone[Entity["City", {"Tokyo", "Tokyo", "Japan"}]]]

which has the representation

TimeObject[{12, 0, 0}, "Instant", "Asia/Tokyo"]

adding one hour to it like

TimeObject[{12, 0, 0}, TimeZone -> LocalTimeZone[Entity["City", {"Tokyo", "Tokyo", "Japan"}]]] + Quantity[1, "Hours"]

does not yield, as I would have expected, 13 pm but instead (once more in InputForm):

TimeObject[{5, 0, 0}, "Instant", "Asia/Tokyo"]

What am I missing here?

5 Replies

Thanks for your feedback and suggestions. At least, I did not overlook something obvious. Going to contact the technical support about this.

Posted 3 years ago

Henrik:

Thanks for figuring out a solution / work-around. But, this still does not make much sense to me. How does the duration of an hour depend on the timezone?

POSTED BY: Mike Besso

Mike,

yes, this is somewhat counterintuitive indeed!

POSTED BY: Henrik Schachner

Hi Karsten,

as it seems one has to use the correct (i.e. the same) time zone to make this work the way you expect it:

$TimeZone = LocalTimeZone[Entity["City", {"Tokyo", "Tokyo", "Japan"}]];
TimeObject[{12, 0, 0}, TimeZone -> LocalTimeZone[Entity["City", {"Tokyo", "Tokyo", "Japan"}]]] + 
  Quantity[1, "Hours"] // InputForm
(*  Out:   TimeObject[{13, 0, 0}, "Instant", "Asia/Tokyo"]  *)
POSTED BY: Henrik Schachner
Posted 3 years ago

Great find.

I'm in Chicago, and I get:

TimeObject[{23, 0, 0}, "Instant", "Asia/Tokyo"]

Looks like it might be a bug. Have you contacted technical support?

POSTED BY: Mike Besso
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract