[Glass] understanding the DateTime instance creation API

Paul DeBruicker via Glass glass at lists.gemtalksystems.com
Fri Jul 15 14:15:40 PDT 2016


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

> Glass at .gemtalksystems

> http://lists.gemtalksystems.com/mailman/listinfo/glass





--
View this message in context: http://forum.world.st/understanding-the-DateTime-instance-creation-API-tp4906741p4906753.html
Sent from the GLASS mailing list archive at Nabble.com.


More information about the Glass mailing list