My TimeZone won't print.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

My TimeZone won't print.

Richard A. O'Keefe
To reproduce this, start up Pharo, create a Playground,
and in the Playground type
     DateAndTime now timeZone
and <Cmd+p> to print it.

But do this in New Zealand.  Changing to <Cmd+i>

On 22/11/17 1:47 PM, [hidden email] wrote:
> Send Pharo-users mailing list submissions to
> [hidden email]

Inspector on a TimeZone (error printing)
...
   self         error printing
   offset       0:13:00:00
   abbreviation nil
   name         nil

The simplest possible change would be to make
TimeZone>>abbreviation be

     ^abbreviation ifNil: [offset printString]

after which
     DateAndTime now timeZone<Cmd+p>
=>  a TimeZone(0:13:00:00)

Another approach would be to paste

                self offset: 12 hours name: 'New Zealand Standard Time'
abbreviation: 'NZST'.
                self offset: 13 hours name: 'New Zealand Daylight Time'
abbreviation: 'NZDT'.

into TimeZone class>>timeZones

but that wouldn't fix the problem for anywhere else.

Reply | Threaded
Open this post in threaded view
|

Re: My TimeZone won't print.

Sven Van Caekenberghe-2
Then you should move ;-)

Of course, if a functional object (your local timezone) exists in your image, it should be able to print itself. That is a bug that we should fix. Your suggested solution is good.

The Timezone class>>#timezones table is very bad though. As is the class Timezone by the way.

This class is a simplification gone too far. It is only useful (and used) to deal with the current offset today, as reported by your VM/OS.

Timezones need DST transitions. Also abbreviations and the names used are not unique and cannot be resolved in 2 directions.

The real solution is something like ZTimestamp's ZTimezone which uses the Olsen database http://en.wikipedia.org/wiki/Tz_database. You can load this package from the Pharo Catalog. It has a certain size (memory cost), of course.

But that would still not fix the problem with abbreviations not being bidirectional. (an offset of 1h can be any of a number of abbreviations).

And it would not solve the problem with timezone offsets in ISO. (+0100 can be tons of timezones, with potentially different rules). Something like the following would be self-containted/context-free unambiguous.

  2017-11-22T09:50:17+Australia/Sydney

But as far as I know, there is no such standard (it is not part of ISO 8601).

> On 22 Nov 2017, at 02:56, Richard A. O'Keefe <[hidden email]> wrote:
>
> To reproduce this, start up Pharo, create a Playground,
> and in the Playground type
>    DateAndTime now timeZone
> and <Cmd+p> to print it.
>
> But do this in New Zealand.  Changing to <Cmd+i>
>
> On 22/11/17 1:47 PM, [hidden email] wrote:
>> Send Pharo-users mailing list submissions to
>> [hidden email]
>
> Inspector on a TimeZone (error printing)
> ...
>  self         error printing
>  offset       0:13:00:00
>  abbreviation nil
>  name         nil
>
> The simplest possible change would be to make
> TimeZone>>abbreviation be
>
>    ^abbreviation ifNil: [offset printString]
>
> after which
>    DateAndTime now timeZone<Cmd+p>
> =>  a TimeZone(0:13:00:00)
>
> Another approach would be to paste
>
> self offset: 12 hours name: 'New Zealand Standard Time' abbreviation: 'NZST'.
> self offset: 13 hours name: 'New Zealand Daylight Time' abbreviation: 'NZDT'.
>
> into TimeZone class>>timeZones
>
> but that wouldn't fix the problem for anywhere else.
>