AbsTime.st
changeset 699 12f456343eea
parent 569 7134eb78cf48
child 795 ff477bad0f2d
equal deleted inserted replaced
698:04533375e12c 699:12f456343eea
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 'From Smalltalk/X, Version:2.10.4 on 8-feb-1995 at 12:46:45 pm'!
       
    14 
       
    15 AbstractTime subclass:#AbsoluteTime
    13 AbstractTime subclass:#AbsoluteTime
    16 	 instanceVariableNames:'osTime'
    14 	 instanceVariableNames:'osTime'
    17 	 classVariableNames:''
    15 	 classVariableNames:''
    18 	 poolDictionaries:''
    16 	 poolDictionaries:''
    19 	 category:'Magnitude-General'
    17 	 category:'Magnitude-General'
    31  inclusion of the above copyright notice.   This software may not
    29  inclusion of the above copyright notice.   This software may not
    32  be provided or otherwise made available to, or used by, any
    30  be provided or otherwise made available to, or used by, any
    33  other person.  No title to or ownership of the software is
    31  other person.  No title to or ownership of the software is
    34  hereby transferred.
    32  hereby transferred.
    35 "
    33 "
    36 !
       
    37 
       
    38 version
       
    39     ^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsTime.st,v 1.17 1995-11-16 23:27:50 cg Exp $'
       
    40 !
    34 !
    41 
    35 
    42 documentation
    36 documentation
    43 "
    37 "
    44     This class represents time values in seconds from 1st. Jan 1970, as
    38     This class represents time values in seconds from 1st. Jan 1970, as
   146     "
   140     "
   147 
   141 
   148     "Modified: 16.11.1995 / 22:49:39 / cg"
   142     "Modified: 16.11.1995 / 22:49:39 / cg"
   149 ! !
   143 ! !
   150 
   144 
   151 !AbsoluteTime methodsFor:'private'!
       
   152 
       
   153 secondsLow
       
   154     "strictly private: return the low part of the seconds"
       
   155 
       
   156     ^ osTime at:1
       
   157 !
       
   158 
       
   159 secondsHi
       
   160     "strictly private: return the hi part of the seconds"
       
   161 
       
   162     ^ osTime at:2 
       
   163 !
       
   164 
       
   165 setSecondsLow:secsLow and:secsHi
       
   166     "strictly private: set the seconds (since whatever)"
       
   167 
       
   168     osTime := Array with:secsLow with:secsHi
       
   169 !
       
   170 
       
   171 setSeconds:secs
       
   172     "strictly private: set the seconds (since whatever)"
       
   173 
       
   174     osTime := Array with:(secs // 16r10000) with:(secs \\ 16r10000)
       
   175 !
       
   176 
       
   177 getSeconds
       
   178     "strictly private: return the seconds (since whatever)"
       
   179 
       
   180     ^ ((osTime at:2) * 16r10000) + (osTime at:1)
       
   181 !
       
   182 
       
   183 fromOSTimeLow:secsLow and:secsHi
       
   184     "strictly private: set the seconds from an OS time (since whatever)"
       
   185 
       
   186     osTime := Array with:secsLow with:secsHi
       
   187 ! !
       
   188 
       
   189 !AbsoluteTime methodsFor:'accessing'!
   145 !AbsoluteTime methodsFor:'accessing'!
   190 
   146 
   191 day
   147 day
   192     "return the day-in-month of the receiver (1..31).
   148     "return the day-in-month of the receiver (1..31).
   193      For compatibility, use instances of Date for this."
   149      For compatibility, use instances of Date for this."
   202     "
   158     "
   203      AbsoluteTime now day 
   159      AbsoluteTime now day 
   204     "
   160     "
   205 !
   161 !
   206 
   162 
       
   163 hours
       
   164     "return the hours (0..23)"
       
   165 
       
   166     |hr|
       
   167 
       
   168     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
       
   169 	hr := hours
       
   170     ].
       
   171     ^ hr
       
   172 
       
   173     "
       
   174      AbsoluteTime now hours 
       
   175     "
       
   176 
       
   177 !
       
   178 
       
   179 minutes
       
   180     "return the minutes (0..59)"
       
   181 
       
   182     |m|
       
   183 
       
   184     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
       
   185 	m := minutes
       
   186     ].
       
   187     ^ m
       
   188 
       
   189     "
       
   190      AbsoluteTime now minutes 
       
   191     "
       
   192 
       
   193 !
       
   194 
   207 month
   195 month
   208     "return the month of the receiver (1..12).
   196     "return the month of the receiver (1..12).
   209      For compatibility, use instances of Date for this."
   197      For compatibility, use instances of Date for this."
   210 
   198 
   211     |m|
   199     |m|
   218     "
   206     "
   219      AbsoluteTime now month
   207      AbsoluteTime now month
   220     "
   208     "
   221 !
   209 !
   222 
   210 
       
   211 seconds
       
   212     "return the seconds (0..59)"
       
   213 
       
   214     |s|
       
   215 
       
   216     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
       
   217 	s := secs
       
   218     ].
       
   219     ^ s
       
   220 
       
   221     "
       
   222      AbsoluteTime now seconds 
       
   223     "
       
   224 
       
   225 !
       
   226 
   223 year
   227 year
   224     "return the year of the receiver i.e. 1992.
   228     "return the year of the receiver i.e. 1992.
   225      For compatibility, use instances of Date for this."
   229      For compatibility, use instances of Date for this."
   226 
   230 
   227     |y|
   231     |y|
   232     ^ y
   236     ^ y
   233 
   237 
   234     "
   238     "
   235      AbsoluteTime now year
   239      AbsoluteTime now year
   236     "
   240     "
   237 !
   241 ! !
   238 
   242 
   239 hours
   243 !AbsoluteTime methodsFor:'arithmetic'!
   240     "return the hours (0..23)"
   244 
   241 
   245 - aTime
   242     |hr|
   246     "return the delta in seconds between 2 times."
   243 
   247 
   244     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
   248     ^ self getSeconds - (aTime getSeconds)
   245 	hr := hours
   249 !
   246     ].
   250 
   247     ^ hr
   251 addDays:numberOfDays
   248 
   252     "return a new instance of myself, numberOfDays afterwards."
   249     "
   253 
   250      AbsoluteTime now hours 
   254     ^ self addSeconds:(numberOfDays * (60 * 60 * 24))
   251     "
   255 
   252 
   256     "
   253 !
   257      |t|
   254 
   258 
   255 minutes
   259      t := AbsoluteTime now.
   256     "return the minutes (0..59)"
   260      t printNL.
   257 
   261      (t addDays:7) printNL
   258     |m|
   262     "
   259 
   263 !
   260     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
   264 
   261 	m := minutes
   265 subtractDays:numberOfDays
   262     ].
   266     "return a new instance of myself, numberOfDays before."
   263     ^ m
   267 
   264 
   268     ^ self subtractSeconds:(numberOfDays * (60 * 60 * 24))
   265     "
   269 
   266      AbsoluteTime now minutes 
   270     "
   267     "
   271      |t|
   268 
   272 
   269 !
   273      t := AbsoluteTime now.
   270 
   274      t printNL.
   271 seconds
   275      (t subtractDays:50) printNL
   272     "return the seconds (0..59)"
   276     "
   273 
       
   274     |s|
       
   275 
       
   276     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
       
   277 	s := secs
       
   278     ].
       
   279     ^ s
       
   280 
       
   281     "
       
   282      AbsoluteTime now seconds 
       
   283     "
       
   284 
       
   285 ! !
   277 ! !
   286 
   278 
   287 !AbsoluteTime methodsFor:'comparing'!
   279 !AbsoluteTime methodsFor:'comparing'!
       
   280 
       
   281 < aTime
       
   282     "return true if the argument, aTime is before the receiver"
       
   283 
       
   284     |myHi otherHi|
       
   285 
       
   286     myHi := self secondsHi. 
       
   287     otherHi := aTime secondsHi.
       
   288     myHi < otherHi ifTrue:[^ true].
       
   289     myHi > otherHi ifTrue:[^ false].
       
   290     ^ self secondsLow < aTime secondsLow
       
   291 !
       
   292 
       
   293 = aTime
       
   294     "return true if the argument, aTime represents the same time"
       
   295 
       
   296     (aTime species == self species) ifFalse:[^ false].
       
   297     ^ (self secondsLow == aTime secondsLow) and:[self secondsHi == aTime secondsHi]
       
   298 !
   288 
   299 
   289 > aTime
   300 > aTime
   290     "return true if the argument, aTime is after the receiver"
   301     "return true if the argument, aTime is after the receiver"
   291 
   302 
   292     |myHi otherHi|
   303     |myHi otherHi|
   296     myHi > otherHi ifTrue:[^ true].
   307     myHi > otherHi ifTrue:[^ true].
   297     myHi < otherHi ifTrue:[^ false].
   308     myHi < otherHi ifTrue:[^ false].
   298     ^ self secondsLow > aTime secondsLow
   309     ^ self secondsLow > aTime secondsLow
   299 !
   310 !
   300 
   311 
   301 < aTime
       
   302     "return true if the argument, aTime is before the receiver"
       
   303 
       
   304     |myHi otherHi|
       
   305 
       
   306     myHi := self secondsHi. 
       
   307     otherHi := aTime secondsHi.
       
   308     myHi < otherHi ifTrue:[^ true].
       
   309     myHi > otherHi ifTrue:[^ false].
       
   310     ^ self secondsLow < aTime secondsLow
       
   311 !
       
   312 
       
   313 = aTime
       
   314     "return true if the argument, aTime represents the same time"
       
   315 
       
   316     (aTime species == self species) ifFalse:[^ false].
       
   317     ^ (self secondsLow == aTime secondsLow) and:[self secondsHi == aTime secondsHi]
       
   318 !
       
   319 
       
   320 hash
   312 hash
   321     "return an integer useful for hashing on times"
   313     "return an integer useful for hashing on times"
   322 
   314 
   323     ^ self getSeconds
   315     ^ self getSeconds
   324 ! !
   316 ! !
   325 
   317 
   326 !AbsoluteTime methodsFor:'converting'!
   318 !AbsoluteTime methodsFor:'converting'!
   327 
   319 
   328 asSeconds
   320 asAbsoluteTime
   329     "return the number of seconds elapsed since whatever time the
   321     "return an AbsoluteTime object from the receiver - thats the receiver."
   330      OperatingSystem bases its time upon. Since this is totally
   322 
   331      OS-dependent, do not interpret the value returned by this method.
   323     ^ self
   332      You can use it to add/subtract seconds or get time deltas, though."
       
   333 
       
   334     ^ self getSeconds
       
   335 
       
   336     "
       
   337      AbsoluteTime now asSeconds
       
   338      AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) 
       
   339      Time hour:23 minutes:33 seconds:0         
       
   340      Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) 
       
   341     "
       
   342 !
   324 !
   343 
   325 
   344 asDate
   326 asDate
   345     "return a Date object from the receiver.
   327     "return a Date object from the receiver.
   346      The returned date will only represent the day - not the timeOfDay."
   328      The returned date will only represent the day - not the timeOfDay."
   356      (AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)) asDate  
   338      (AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600)) asDate  
   357     "
   339     "
   358 
   340 
   359 !
   341 !
   360 
   342 
       
   343 asSeconds
       
   344     "return the number of seconds elapsed since whatever time the
       
   345      OperatingSystem bases its time upon. Since this is totally
       
   346      OS-dependent, do not interpret the value returned by this method.
       
   347      You can use it to add/subtract seconds or get time deltas, though."
       
   348 
       
   349     ^ self getSeconds
       
   350 
       
   351     "
       
   352      AbsoluteTime now asSeconds
       
   353      AbsoluteTime fromSeconds:(AbsoluteTime now asSeconds + 3600) 
       
   354      Time hour:23 minutes:33 seconds:0         
       
   355      Time fromSeconds:((Time hour:23 minutes:33 seconds:0) asSeconds + 3600) 
       
   356     "
       
   357 !
       
   358 
   361 asTime
   359 asTime
   362     "return a Time object from the receiver.
   360     "return a Time object from the receiver.
   363      The returned time will only represent the timeOfDay - not the day."
   361      The returned time will only represent the timeOfDay - not the day."
   364 
   362 
   365     ^ Time fromOSTime:osTime
   363     ^ Time fromOSTime:osTime
   366 
   364 
   367     "
   365     "
   368      AbsoluteTime now  
   366      AbsoluteTime now  
   369      AbsoluteTime now asTime
   367      AbsoluteTime now asTime
   370      (AbsoluteTime now addTime:3600) asTime 
   368      (AbsoluteTime now addTime:3600) asTime 
   371     "
       
   372 !
       
   373 
       
   374 asAbsoluteTime
       
   375     "return an AbsoluteTime object from the receiver - thats the receiver."
       
   376 
       
   377     ^ self
       
   378 ! !
       
   379 
       
   380 !AbsoluteTime methodsFor:'arithmetic'!
       
   381 
       
   382 - aTime
       
   383     "return the delta in seconds between 2 times."
       
   384 
       
   385     ^ self getSeconds - (aTime getSeconds)
       
   386 !
       
   387 
       
   388 addDays:numberOfDays
       
   389     "return a new instance of myself, numberOfDays afterwards."
       
   390 
       
   391     ^ self addSeconds:(numberOfDays * (60 * 60 * 24))
       
   392 
       
   393     "
       
   394      |t|
       
   395 
       
   396      t := AbsoluteTime now.
       
   397      t printNL.
       
   398      (t addDays:7) printNL
       
   399     "
       
   400 !
       
   401 
       
   402 subtractDays:numberOfDays
       
   403     "return a new instance of myself, numberOfDays before."
       
   404 
       
   405     ^ self subtractSeconds:(numberOfDays * (60 * 60 * 24))
       
   406 
       
   407     "
       
   408      |t|
       
   409 
       
   410      t := AbsoluteTime now.
       
   411      t printNL.
       
   412      (t subtractDays:50) printNL
       
   413     "
   369     "
   414 ! !
   370 ! !
   415 
   371 
   416 !AbsoluteTime methodsFor:'printing & storing'!
   372 !AbsoluteTime methodsFor:'printing & storing'!
   417 
   373 
   461      AbsoluteTime now storeString 
   417      AbsoluteTime now storeString 
   462 
   418 
   463      AbsoluteTime readFrom:(AbsoluteTime now storeString) readStream
   419      AbsoluteTime readFrom:(AbsoluteTime now storeString) readStream
   464     "
   420     "
   465 ! !
   421 ! !
       
   422 
       
   423 !AbsoluteTime methodsFor:'private'!
       
   424 
       
   425 fromOSTimeLow:secsLow and:secsHi
       
   426     "strictly private: set the seconds from an OS time (since whatever)"
       
   427 
       
   428     osTime := Array with:secsLow with:secsHi
       
   429 !
       
   430 
       
   431 getSeconds
       
   432     "strictly private: return the seconds (since whatever)"
       
   433 
       
   434     ^ ((osTime at:2) * 16r10000) + (osTime at:1)
       
   435 !
       
   436 
       
   437 secondsHi
       
   438     "strictly private: return the hi part of the seconds"
       
   439 
       
   440     ^ osTime at:2 
       
   441 !
       
   442 
       
   443 secondsLow
       
   444     "strictly private: return the low part of the seconds"
       
   445 
       
   446     ^ osTime at:1
       
   447 !
       
   448 
       
   449 setSeconds:secs
       
   450     "strictly private: set the seconds (since whatever)"
       
   451 
       
   452     osTime := Array with:(secs // 16r10000) with:(secs \\ 16r10000)
       
   453 !
       
   454 
       
   455 setSecondsLow:secsLow and:secsHi
       
   456     "strictly private: set the seconds (since whatever)"
       
   457 
       
   458     osTime := Array with:secsLow with:secsHi
       
   459 ! !
       
   460 
       
   461 !AbsoluteTime class methodsFor:'documentation'!
       
   462 
       
   463 version
       
   464     ^ '$Header: /cvs/stx/stx/libbasic/Attic/AbsTime.st,v 1.18 1995-12-07 21:31:29 cg Exp $'
       
   465 ! !