understanding the DateTime instance creation API

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

understanding the DateTime instance creation API

GLASS mailing list
I'm trying to create a DateTime in a 3.3.1 stone set to use UTC as its current & default timezone.

When I specify the year, month, day, hour, minute, second and time zone I sometimes wind up with DateTimes I don't understand.  


As an example if I run the below code the two ISO8601 strings that print are for UTC '2016-07-15T10:10:10+0000' and for PST '2016-07-15T17:10:10-0700'.  


I think the PST ISO8601 string generated by GemStone should be  '2016-07-15T10:10:10-0700'


If I then go to another platform e.g. wolframalpha.com and convert from the ISO strings to Unix time, the difference between the UTC ISO8601 string (1468577410 in unix time) and the GemStone generated PST ISO8601 string (1468627810 in unix time) is greater (14 hours) than the difference in their time zone offsets (7 hours).  


What am I doing wrong?  IT seems like I can only reliably specify a DateTime by setting the year, month, day, hour, minute, second and time zone if I use UTC as the time zone.  

Thanks for any guidance you can provide.

Paul




| yr month day hour min second utc pst utcTime pstTime |
  yr := 2016.
  month := 7.
  day := 15.
  hour := 10.
  min := 10.
  second := 10.
  utc := TimeZone named: 'UTC'.
  pst := TimeZone named: 'America/Los_Angeles'.

  utcTime := DateTime
    newWithYear: yr
    month: month
    day: day
    hours: hour
    minutes: min
    seconds: second
    timeZone: utc.

  pstTime := DateTime
    newWithYear: yr
    month: month
    day: day
    hours: hour
    minutes: min
    seconds: second
    timeZone: pst.

  ^ Array
    with: (Array with: utcTime with: utcTime hour with: utcTime asStringISO8601)
    with: (Array with: pstTime with: pstTime hour with: pstTime asStringISO8601)
_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

GLASS mailing list
Could you provide some Smalltalk code that exhibits the problems so I
can understand how you are creating the various instances of DateTime?

There is "squeak compatible" protocol and GemStone protocol so the
fix/answer to your question will depend upon which methods you are using
... it could be that you are hitting base image bugs or bugs introduced
by the GLASS/GsDevKit code...

Dale

On 07/15/2016 12:47 PM, PAUL DEBRUICKER via Glass wrote:

> I'm trying to create a DateTime in a 3.3.1 stone set to use UTC as its current & default timezone.
>
> When I specify the year, month, day, hour, minute, second and time zone I sometimes wind up with DateTimes I don't understand.
>
>
> As an example if I run the below code the two ISO8601 strings that print are for UTC '2016-07-15T10:10:10+0000' and for PST '2016-07-15T17:10:10-0700'.
>
>
> I think the PST ISO8601 string generated by GemStone should be  '2016-07-15T10:10:10-0700'
>
>
> If I then go to another platform e.g. wolframalpha.com and convert from the ISO strings to Unix time, the difference between the UTC ISO8601 string (1468577410 in unix time) and the GemStone generated PST ISO8601 string (1468627810 in unix time) is greater (14 hours) than the difference in their time zone offsets (7 hours).
>
>
> What am I doing wrong?  IT seems like I can only reliably specify a DateTime by setting the year, month, day, hour, minute, second and time zone if I use UTC as the time zone.
>
> Thanks for any guidance you can provide.
>
> Paul
>
>
>
>
> | yr month day hour min second utc pst utcTime pstTime |
>    yr := 2016.
>    month := 7.
>    day := 15.
>    hour := 10.
>    min := 10.
>    second := 10.
>    utc := TimeZone named: 'UTC'.
>    pst := TimeZone named: 'America/Los_Angeles'.
>
>    utcTime := DateTime
>      newWithYear: yr
>      month: month
>      day: day
>      hours: hour
>      minutes: min
>      seconds: second
>      timeZone: utc.
>
>    pstTime := DateTime
>      newWithYear: yr
>      month: month
>      day: day
>      hours: hour
>      minutes: min
>      seconds: second
>      timeZone: pst.
>
>    ^ Array
>      with: (Array with: utcTime with: utcTime hour with: utcTime asStringISO8601)
>      with: (Array with: pstTime with: pstTime hour with: pstTime asStringISO8601)
> _______________________________________________
> Glass mailing list
> [hidden email]
> http://lists.gemtalksystems.com/mailman/listinfo/glass

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

Paul DeBruicker
Hi Dale,

I pasted my testDt.st tode file below my name in my prior message.  If you run it you get two arrays with containing the DateTimes, their #hour, and the ISO8601 string.



also interesting is if I use the #newGmtWithYear:........   method rather than the #newWithYear:....... method the duration you get when subtracting the utcTime from the pstTime is zero, but the ISO8601 strings are correct.  When using #newWithYear... the duration is correct at -7 hrs but the ISO8601 strings are wrong.


Hope this helps


Paul




GLASS mailing list wrote
Could you provide some Smalltalk code that exhibits the problems so I
can understand how you are creating the various instances of DateTime?

There is "squeak compatible" protocol and GemStone protocol so the
fix/answer to your question will depend upon which methods you are using
... it could be that you are hitting base image bugs or bugs introduced
by the GLASS/GsDevKit code...

Dale

On 07/15/2016 12:47 PM, PAUL DEBRUICKER via Glass wrote:
> I'm trying to create a DateTime in a 3.3.1 stone set to use UTC as its current & default timezone.
>
> When I specify the year, month, day, hour, minute, second and time zone I sometimes wind up with DateTimes I don't understand.
>
>
> As an example if I run the below code the two ISO8601 strings that print are for UTC '2016-07-15T10:10:10+0000' and for PST '2016-07-15T17:10:10-0700'.
>
>
> I think the PST ISO8601 string generated by GemStone should be  '2016-07-15T10:10:10-0700'
>
>
> If I then go to another platform e.g. wolframalpha.com and convert from the ISO strings to Unix time, the difference between the UTC ISO8601 string (1468577410 in unix time) and the GemStone generated PST ISO8601 string (1468627810 in unix time) is greater (14 hours) than the difference in their time zone offsets (7 hours).
>
>
> What am I doing wrong?  IT seems like I can only reliably specify a DateTime by setting the year, month, day, hour, minute, second and time zone if I use UTC as the time zone.
>
> Thanks for any guidance you can provide.
>
> Paul
>
>
>
>
> | yr month day hour min second utc pst utcTime pstTime |
>    yr := 2016.
>    month := 7.
>    day := 15.
>    hour := 10.
>    min := 10.
>    second := 10.
>    utc := TimeZone named: 'UTC'.
>    pst := TimeZone named: 'America/Los_Angeles'.
>
>    utcTime := DateTime
>      newWithYear: yr
>      month: month
>      day: day
>      hours: hour
>      minutes: min
>      seconds: second
>      timeZone: utc.
>
>    pstTime := DateTime
>      newWithYear: yr
>      month: month
>      day: day
>      hours: hour
>      minutes: min
>      seconds: second
>      timeZone: pst.
>
>    ^ Array
>      with: (Array with: utcTime with: utcTime hour with: utcTime asStringISO8601)
>      with: (Array with: pstTime with: pstTime hour with: pstTime asStringISO8601)
> _______________________________________________
> Glass mailing list
> [hidden email]
> http://lists.gemtalksystems.com/mailman/listinfo/glass

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

GLASS mailing list


On 07/15/2016 12:37 PM, Paul DeBruicker via Glass wrote:
> Hi Dale,
>
> I pasted my testDt.st tode file below my name in my prior message.  If you
> run it you get two arrays with containing the DateTimes, their #hour, and
> the ISO8601 string.
>
haha, your message up to the signature fit exactly in the window in my
mail browser and didn't bother checking the scroll bar to see if there
was more:)

When I run your code I get the following:

1@       -> anArray( 15/07/2016 03:10:10, 3, '2016-07-15T03:10:10+0000')
2@       -> anArray( 15/07/2016 10:10:10, 10, '2016-07-15T10:10:10-0700')

Which I think is what you are expecting ... so there must be something
else going on? What is the timeZone for the machine that your stone is
run on?

Presumably this is where the bug is asserting itself ...

Dale

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

Paul DeBruicker
Hi Dale,


I get


1@       -> anArray( 15/07/2016 10:10:10, 10, '2016-07-15T10:10:10+0000', )
2@       -> anArray( 15/07/2016 17:10:10, 17, '2016-07-15T17:10:10-0700', )

And I expect the last parameter of the second array to be '2016-07-15T10:10:10-0700'.   I'm not sure what the first should be. I think the first parameter is right because DateTimes are printed as UTC inside GemStone.  I think the #hour method which returns the hour in 'local' time should not be used in the ISO8601 string and instead a hourInTimeZone or somesuch should be used.  


I set the stone's timezone with:


printit
| osTZ |
System beginTransaction.
osTZ := TimeZone named:'UTC'.
osTZ installAsCurrentTimeZone.
TimeZone default: osTZ.
TimeZoneInfo default: osTZ.
System commitTransaction.
%

Both "TimeZone current"  and "TimeZone default" print 'UTC'.  


Paul







GLASS mailing list wrote
On 07/15/2016 12:37 PM, Paul DeBruicker via Glass wrote:
> Hi Dale,
>
> I pasted my testDt.st tode file below my name in my prior message.  If you
> run it you get two arrays with containing the DateTimes, their #hour, and
> the ISO8601 string.
>
haha, your message up to the signature fit exactly in the window in my
mail browser and didn't bother checking the scroll bar to see if there
was more:)

When I run your code I get the following:

1@       -> anArray( 15/07/2016 03:10:10, 3, '2016-07-15T03:10:10+0000')
2@       -> anArray( 15/07/2016 10:10:10, 10, '2016-07-15T10:10:10-0700')

Which I think is what you are expecting ... so there must be something
else going on? What is the timeZone for the machine that your stone is
run on?

Presumably this is where the bug is asserting itself ...

Dale

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

Paul DeBruicker
And just FWIW I'd switch the DateTime default printing to the ISO8601 string, and provide a default method to parse ISO8601 strings.


Paul DeBruicker wrote
Hi Dale,


I get


1@       -> anArray( 15/07/2016 10:10:10, 10, '2016-07-15T10:10:10+0000', )
2@       -> anArray( 15/07/2016 17:10:10, 17, '2016-07-15T17:10:10-0700', )

And I expect the last parameter of the second array to be '2016-07-15T10:10:10-0700'.   I'm not sure what the first should be. I think the first parameter is right because DateTimes are printed as UTC inside GemStone.  I think the #hour method which returns the hour in 'local' time should not be used in the ISO8601 string and instead a hourInTimeZone or somesuch should be used.  


I set the stone's timezone with:


printit
| osTZ |
System beginTransaction.
osTZ := TimeZone named:'UTC'.
osTZ installAsCurrentTimeZone.
TimeZone default: osTZ.
TimeZoneInfo default: osTZ.
System commitTransaction.
%

Both "TimeZone current"  and "TimeZone default" print 'UTC'.  


Paul







GLASS mailing list wrote
On 07/15/2016 12:37 PM, Paul DeBruicker via Glass wrote:
> Hi Dale,
>
> I pasted my testDt.st tode file below my name in my prior message.  If you
> run it you get two arrays with containing the DateTimes, their #hour, and
> the ISO8601 string.
>
haha, your message up to the signature fit exactly in the window in my
mail browser and didn't bother checking the scroll bar to see if there
was more:)

When I run your code I get the following:

1@       -> anArray( 15/07/2016 03:10:10, 3, '2016-07-15T03:10:10+0000')
2@       -> anArray( 15/07/2016 10:10:10, 10, '2016-07-15T10:10:10-0700')

Which I think is what you are expecting ... so there must be something
else going on? What is the timeZone for the machine that your stone is
run on?

Presumably this is where the bug is asserting itself ...

Dale

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

GLASS mailing list
In reply to this post by Paul DeBruicker
Paul,

I've submitted bug46315, because it definitely looks like DateTime is
broken.

I've expanded your example to include DateAndTime results and I believe
that DateAndTime is getting the correct answers. Also DateAndTime has
the default printString and parsing methods that you desire.

Here are the results:

1@       -> anArray( DateTime, 15/07/2016 03:10:10, 3,
'2016-07-15T03:10:10+0000', )
2@       -> anArray( DateAndTime, 2016-07-15T10:10:10+00:00, 10,
'2016-07-15T10:10:10+00:00', )
3@       -> anArray( DateTime, 15/07/2016 10:10:10, 10,
'2016-07-15T10:10:10-0700', )
4@       -> anArray( DateAndTime, 2016-07-15T10:10:10-07:00, 10,
'2016-07-15T10:10:10-07:00', )


and the code:

| yr month day hour min second utc pst utcTime pstTime utcAndTime
pstAndTime |
   yr := 2016.
   month := 7.
   day := 15.
   hour := 10.
   min := 10.
   second := 10.
   utc := TimeZone named: 'UTC'.
   pst := TimeZone named: 'America/Los_Angeles'.
   utcTime := DateTime
     newWithYear: yr
     month: month
     day: day
     hours: hour
     minutes: min
     seconds: second
     timeZone: utc.
   utcAndTime := DateAndTime
     year: yr
     month: month
     day: day
     hour: hour
     minute: min
     second: second
     offset: 0 hours.
   pstTime := DateTime
     newWithYear: yr
     month: month
     day: day
     hours: hour
     minutes: min
     seconds: second
     timeZone: pst.
   pstAndTime := DateAndTime
     year: yr
     month: month
     day: day
     hour: hour
     minute: min
     second: second
     offset: -7 hours.
   ^ {(Array
     with: utcTime class
     with: utcTime
     with: utcTime hour
     with: utcTime asStringISO8601).
   (Array
     with: utcAndTime class
     with: utcAndTime
     with: utcAndTime hour
     with: utcAndTime asString).
   (Array
     with: pstTime class
     with: pstTime
     with: pstTime hour
     with: pstTime asStringISO8601).
   (Array
     with: pstAndTime class
     with: pstAndTime
     with: pstAndTime hour
     with: pstAndTime asString)}


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

Paul DeBruicker
Thanks Dale.


I modified the asStringISO8601 to

DateTime>>#asStringISO8601
  "yyyy-mm-ddThh:mm:ss+zzzz"

  | string offset offsetHours offsetMinutes |
  string := self
    asStringUsingFormat: #(3 2 1 $- 1 1 $: true true false true true).
  string at: 11 put: $T.
  string := string first: 19.
  offset := timeZone offsetAtLocal: self.
  string
    add:
      (offset < 0
        ifTrue: [ $- ]
        ifFalse: [ $+ ]).
  offset := offset abs // 60.
  offsetHours := offset // 60.
  offsetMinutes := offset \\ 60.
  offsetHours < 10
    ifTrue: [ string add: $0 ].
  string addAll: offsetHours printString.
  offsetMinutes < 10
    ifTrue: [ string add: $0 ].
  string addAll: offsetMinutes printString.
  ^ string


And it seems to have fixed my current problem.


GLASS mailing list wrote
Paul,

I've submitted bug46315, because it definitely looks like DateTime is
broken.

I've expanded your example to include DateAndTime results and I believe
that DateAndTime is getting the correct answers. Also DateAndTime has
the default printString and parsing methods that you desire.

Here are the results:

1@       -> anArray( DateTime, 15/07/2016 03:10:10, 3,
'2016-07-15T03:10:10+0000', )
2@       -> anArray( DateAndTime, 2016-07-15T10:10:10+00:00, 10,
'2016-07-15T10:10:10+00:00', )
3@       -> anArray( DateTime, 15/07/2016 10:10:10, 10,
'2016-07-15T10:10:10-0700', )
4@       -> anArray( DateAndTime, 2016-07-15T10:10:10-07:00, 10,
'2016-07-15T10:10:10-07:00', )


and the code:

| yr month day hour min second utc pst utcTime pstTime utcAndTime
pstAndTime |
   yr := 2016.
   month := 7.
   day := 15.
   hour := 10.
   min := 10.
   second := 10.
   utc := TimeZone named: 'UTC'.
   pst := TimeZone named: 'America/Los_Angeles'.
   utcTime := DateTime
     newWithYear: yr
     month: month
     day: day
     hours: hour
     minutes: min
     seconds: second
     timeZone: utc.
   utcAndTime := DateAndTime
     year: yr
     month: month
     day: day
     hour: hour
     minute: min
     second: second
     offset: 0 hours.
   pstTime := DateTime
     newWithYear: yr
     month: month
     day: day
     hours: hour
     minutes: min
     seconds: second
     timeZone: pst.
   pstAndTime := DateAndTime
     year: yr
     month: month
     day: day
     hour: hour
     minute: min
     second: second
     offset: -7 hours.
   ^ {(Array
     with: utcTime class
     with: utcTime
     with: utcTime hour
     with: utcTime asStringISO8601).
   (Array
     with: utcAndTime class
     with: utcAndTime
     with: utcAndTime hour
     with: utcAndTime asString).
   (Array
     with: pstTime class
     with: pstTime
     with: pstTime hour
     with: pstTime asStringISO8601).
   (Array
     with: pstAndTime class
     with: pstAndTime
     with: pstAndTime hour
     with: pstAndTime asString)}


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: understanding the DateTime instance creation API

GLASS mailing list
Thanks Paul, I've added this to the bug report ...

Dale

On 07/15/2016 02:15 PM, Paul DeBruicker via Glass wrote:

> DateTime>>#asStringISO8601
>    "yyyy-mm-ddThh:mm:ss+zzzz"
>
>    | string offset offsetHours offsetMinutes |
>    string := self
>      asStringUsingFormat: #(3 2 1 $- 1 1 $: true true false true true).
>    string at: 11 put: $T.
>    string := string first: 19.
>    offset := timeZone offsetAtLocal: self.
>    string
>      add:
>        (offset < 0
>          ifTrue: [ $- ]
>          ifFalse: [ $+ ]).
>    offset := offset abs // 60.
>    offsetHours := offset // 60.
>    offsetMinutes := offset \\ 60.
>    offsetHours < 10
>      ifTrue: [ string add: $0 ].
>    string addAll: offsetHours printString.
>    offsetMinutes < 10
>      ifTrue: [ string add: $0 ].
>    string addAll: offsetMinutes printString.
>    ^ string

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass