Issue 3236 in pharo: Cuis DateAndTime Enhancement

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

Issue 3236 in pharo: Cuis DateAndTime Enhancement

pharo
Status: Accepted
Owner: stephane.ducasse
Labels: Type-Squeak

New issue 3236 by stephane.ducasse: Cuis DateAndTime Enhancement
http://code.google.com/p/pharo/issues/detail?id=3236

Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ul.512.mcz

==================== Summary ====================

Name: Kernel-ul.512
Author: ul
Time: 7 November 2010, 12:05:13.149 am
UUID: f35cd221-68a5-f04b-b6bc-d07df326b3d3
Ancestors: Kernel-nice.511

- DateAndTime startup enhancement from Cuis part 1

=============== Diff against Kernel-nice.511 ===============

Item was changed:
  Magnitude subclass: #DateAndTime
        instanceVariableNames: 'seconds offset jdn nanos'
+       classVariableNames: 'ClockProvider DaysSinceEpoch LastMilliSeconds  
LastTick LastTickSemaphore LocalTimeZone MilliSecondOffset OffsetsAreValid'
-       classVariableNames: 'ClockProvider DaysSinceEpoch LastMilliSeconds  
LastTick LastTickSemaphore LocalTimeZone MilliSecondOffset'
        poolDictionaries: 'ChronologyConstants'
        category: 'Kernel-Chronology'!

  !DateAndTime commentStamp: 'brp 5/13/2003 08:07' prior: 0!
  I represent a point in UTC time as defined by ISO 8601. I have zero  
duration.


  My implementation uses three SmallIntegers
   and a Duration:
  jdn           - julian day number.
  seconds       - number of seconds since midnight.
  nanos - the number of nanoseconds since the second.

  offset        - duration from UTC.

  The nanosecond attribute is almost always zero but it defined for full ISO  
compliance and is suitable for timestamping.
  !

Item was added:
+ (PackageInfo named: 'Kernel') postscript: 'DateAndTime classPool at:  
#OffsetsAreValid put: true'!



Reply | Threaded
Open this post in threaded view
|

Re: Issue 3236 in pharo: Cuis DateAndTime Enhancement

pharo
Updates:
        Status: FixedWaitingToBePharoed

Comment #1 on issue 3236 by stephane.ducasse: Cuis DateAndTime Enhancement
http://code.google.com/p/pharo/issues/detail?id=3236

Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ul.513.mcz

==================== Summary ====================

Name: Kernel-ul.513
Author: ul
Time: 7 November 2010, 12:08:10.875 am
UUID: 887f4907-c347-2e45-8d2e-dd7814ac4248
Ancestors: Kernel-ul.512

- DateAndTime startup enhancement from Cuis part 2

=============== Diff against Kernel-ul.512 ===============

Item was changed:
  ----- Method: DateAndTime class>>initializeOffsets (in  
category 'initialize-release') -----
+ initializeOffsets
+       | durationSinceEpoch secondsSinceMidnight nowSecs |
+       LastTick := 0.
+       nowSecs := self clock secondsWhenClockTicks.
+       LastMilliSeconds := self millisecondClockValue.
+       durationSinceEpoch := Duration
+               days: SqueakEpoch
+               hours: 0
+               minutes: 0
+               seconds: nowSecs.
+       DaysSinceEpoch := durationSinceEpoch days.
+       secondsSinceMidnight := (durationSinceEpoch -
+               (Duration
+                       days: DaysSinceEpoch
+                       hours: 0
+                       minutes: 0
+                       seconds: 0)) asSeconds.
+       MilliSecondOffset := secondsSinceMidnight * 1000 - LastMilliSeconds!
- initializeOffsets
-
-       | epochianSeconds secondsSinceMidnight nowSecs  |
-
-       LastTick := 0.
-
-       nowSecs :=  self clock secondsWhenClockTicks.
-       LastMilliSeconds := self millisecondClockValue.
-
-       epochianSeconds := Duration days: SqueakEpoch hours: 0 minutes: 0  
seconds: nowSecs.
-
-       DaysSinceEpoch := epochianSeconds days.
-
-       secondsSinceMidnight := (epochianSeconds - (Duration days:  
DaysSinceEpoch hours: 0 minutes: 0 seconds: 0)) asSeconds.
-
-       MilliSecondOffset := (secondsSinceMidnight * 1000 -  
LastMilliSeconds)
- !

Item was changed:
  ----- Method: DateAndTime class>>milliSecondsSinceMidnight (in  
category 'squeak protocol') -----
  milliSecondsSinceMidnight
-
        | msm msClock |
-
-       msClock := self millisecondClockValue.

+       "This is usually only during system startup..."
+       self waitForOffsets.
-       (
- msClock < LastMilliSeconds)
-               ifTrue:[ "rolled over" MilliSecondOffset :=  
MilliSecondOffset + (SmallInteger maxVal // 2) + 1 ].

+       msClock := self millisecondClockValue.
+       msClock < LastMilliSeconds ifTrue: [ "rolled over"
+               MilliSecondOffset := MilliSecondOffset + (SmallInteger  
maxVal // 2) + 1 ].
        LastMilliSeconds := msClock.
+       [
+       msm := msClock + MilliSecondOffset.
+       msm >= 86400000 ] whileTrue: [
+               "next day"
+               LastTick := -1.
+               DaysSinceEpoch := DaysSinceEpoch + 1.
+               MilliSecondOffset := MilliSecondOffset - 86400000 ].
-
-       [ msm := msClock + MilliSecondOffset.
-        (msm >= 86400000) ]
-               whileTrue: [ "next day"
-                       LastTick := -1.
-                       DaysSinceEpoch := DaysSinceEpoch + 1.
-                       MilliSecondOffset := MilliSecondOffset - 86400000 ].
-
        "day rolled over sanity check"
+       (LastTick = -1 and: [
+               (Duration
+                       days: SqueakEpoch
+                       hours: 0
+                       minutes: 0
+                       seconds: self clock totalSeconds) days ~=  
DaysSinceEpoch ]) ifTrue: [
+               self initializeOffsets.
+               ^ self milliSecondsSinceMidnight ].
+       ^ msm.!
-       ((LastTick = -1) and: [
-               (Duration days: SqueakEpoch hours: 0 minutes: 0  
seconds:                                                                
(self clock totalSeconds)) days ~= DaysSinceEpoch ])
-               ifTrue:
-                               [  self initializeOffsets.
-                                ^ self milliSecondsSinceMidnight ].
-
- ^msm
-
-
-
- !

Item was changed:
  ----- Method: DateAndTime class>>now (in category 'ansi protocol') -----
  now
        | nanoTicks msm |

        nanoTicks := (msm := self milliSecondsSinceMidnight) * 1000000.

        (LastTick < nanoTicks) ifTrue: [
                LastTick := nanoTicks.
                ^ self todayAtMilliSeconds: msm].

+       LastTickSemaphore critical: [
-       LastTickSemaphore critical: [
                LastTick :=  LastTick + 1.
                ^ self todayAtNanoSeconds: LastTick]

  "
  [ 10000 timesRepeat: [ self now. ] ] timeToRun / 10000.0 .

  If calls to DateAndTime-c-#now are within a single millisecond the  
semaphore code
  to ensure that (self now <= self now) slows things down considerably by a  
factor of about 20.

  The actual speed of a single call to DateAndTime-now in milliseconds is
  demonstrated by the unguarded method below.

  [ 100000 timesRepeat: [ self todayAtMilliSeconds: (self  
milliSecondsSinceMidnight) ] ] timeToRun / 100000.0 .  0.00494 0.00481  
0.00492 0.00495

  "!

Item was changed:
  ----- Method: DateAndTime class>>startUp: (in  
category 'initialize-release') -----
+ startUp: resuming
+       resuming ifFalse: [ ^ self ].
+       OffsetsAreValid := false.
+       [
+               self initializeOffsets.
+               OffsetsAreValid := true
+       ] forkAt: Processor userInterruptPriority.!
- startUp: resuming
-
-       resuming ifFalse: [^ self].
-
-       [ self initializeOffsets ] fork.
-
- !

Item was changed:
  ----- Method: DateAndTime class>>todayAtMilliSeconds: (in category 'squeak  
protocol') -----
  todayAtMilliSeconds: milliSecondsSinceMidnight

+       "This is usually only during system startup..."
+       self waitForOffsets.
+
         ^ self basicNew
                        setJdn: DaysSinceEpoch
                        seconds: (milliSecondsSinceMidnight // 1000)
                        nano: (milliSecondsSinceMidnight  \\ 1000 * 1000000  
)
                        offset: self localOffset

  "
+ [ 100000 timesRepeat: [ self fromMilliSeconds: self  
milliSecondsSinceMidnight. ] ] timeToRun.
- [ 100000 timesRepeat: [ self fromMilliSeconds: self  
milliSecondsSinceMidnight. ] ] timeToRun.
  "!

Item was changed:
  ----- Method: DateAndTime class>>todayAtNanoSeconds: (in category 'squeak  
protocol') -----
  todayAtNanoSeconds: nanoSecondsSinceMidnight

+       "This is usually only during system startup..."
+       self waitForOffsets.
+
        ^ self basicNew
                        setJdn: DaysSinceEpoch
                        seconds: (nanoSecondsSinceMidnight // 1000000000)
                        nano: (nanoSecondsSinceMidnight  \\ 1000000000  )
                        offset: self localOffset
   !

Item was added:
+ ----- Method: DateAndTime class>>waitForOffsets (in  
category 'initialize-release') -----
+ waitForOffsets
+       OffsetsAreValid ifFalse: [
+               [
+                       (Delay forSeconds: 1) wait.
+                       OffsetsAreValid
+               ] whileFalse
+       ]!