Time.st
changeset 17141 e2964d1d3d6f
parent 17136 0ef1bb251905
child 17162 682a35f6f035
equal deleted inserted replaced
17140:9369deba01dc 17141:e2964d1d3d6f
   543 !Time methodsFor:'comparing'!
   543 !Time methodsFor:'comparing'!
   544 
   544 
   545 < aTime
   545 < aTime
   546     "return true if the receiver is before the argument"
   546     "return true if the receiver is before the argument"
   547 
   547 
       
   548     |milliseconds|
       
   549 
   548     aTime class == self class ifTrue:[
   550     aTime class == self class ifTrue:[
   549 	^ timeEncoding < aTime timeEncoding
   551         ^ timeEncoding < aTime timeEncoding
   550     ].
   552     ].
   551     ^ self getMilliseconds < aTime getMilliseconds
   553     aTime isNumber ifTrue:[
       
   554         "backward compatibility for old code, which expects (time1 - time2) to return seconds"    
       
   555         milliseconds := (aTime * 1000) asInteger.   "integer seconds"
       
   556     ] ifFalse:[
       
   557         milliseconds := aTime getMilliseconds.
       
   558     ].
       
   559     ^ self getMilliseconds < milliseconds
       
   560 
       
   561     "
       
   562         (Timestamp now + 10) - Timestamp now  < 10
       
   563         (Timestamp now + 10) - Timestamp now  < 11
       
   564     "
       
   565 !
       
   566 
       
   567 <= aTime
       
   568     "return true if the receiver is before the argument"
       
   569 
       
   570     |milliseconds|
       
   571 
       
   572     aTime class == self class ifTrue:[
       
   573         ^ timeEncoding <= aTime timeEncoding
       
   574     ].
       
   575     aTime isNumber ifTrue:[
       
   576         "backward compatibility for old code, which expects (time1 - time2) to return seconds"    
       
   577         milliseconds := (aTime * 1000) asInteger.   "integer seconds"
       
   578     ] ifFalse:[
       
   579         milliseconds := aTime getMilliseconds.
       
   580     ].
       
   581     ^ self getMilliseconds <= milliseconds
       
   582 
       
   583     "
       
   584         (Timestamp now + 10) - Timestamp now  <= 10
       
   585         (Timestamp now + 10) - Timestamp now  <= 11
       
   586         (Timestamp now + 10) - Timestamp now  <= 9
       
   587     "
   552 !
   588 !
   553 
   589 
   554 = aTime
   590 = aTime
   555     "return true if the argument, aTime represents the same timeOfDay"
   591     "return true if the argument, aTime represents the same timeOfDay"
   556 
   592 
       
   593     |milliseconds|
       
   594 
   557     aTime class == self class ifTrue:[
   595     aTime class == self class ifTrue:[
   558 	^ timeEncoding = aTime timeEncoding
   596         ^ timeEncoding = aTime timeEncoding
   559     ].
   597     ].
   560     (aTime species == self species) ifFalse:[^ false].
   598     aTime isNumber ifTrue:[
   561     ^ self getMilliseconds = aTime getMilliseconds
   599         "backward compatibility for old code, which expects (time1 - time2) to return seconds"    
   562 
   600         milliseconds := (aTime * 1000) asInteger.   "integer seconds"
   563     "Modified: / 18-07-2007 / 14:16:34 / cg"
   601     ] ifFalse:[
       
   602         aTime species == self species ifFalse:[^ false].
       
   603         milliseconds := aTime getMilliseconds.
       
   604     ].
       
   605     ^ self getMilliseconds = milliseconds
       
   606 
       
   607     "
       
   608         (Timestamp now + 10) - Timestamp now  = 10
       
   609         (Timestamp now + 10) - Timestamp now  = 9
       
   610     "
   564 !
   611 !
   565 
   612 
   566 > aTime
   613 > aTime
   567     "return true if the receiver is before the argument"
   614     "return true if the receiver is before the argument"
   568 
   615 
       
   616     |milliseconds|
       
   617 
   569     aTime class == self class ifTrue:[
   618     aTime class == self class ifTrue:[
   570 	^ timeEncoding > aTime timeEncoding
   619         ^ timeEncoding > aTime timeEncoding
   571     ].
   620     ].
   572     ^ self getMilliseconds > aTime getMilliseconds
   621     aTime isNumber ifTrue:[
       
   622         "backward compatibility for old code, which expects (time1 - time2) to return seconds"    
       
   623         milliseconds := (aTime * 1000) asInteger.   "integer seconds"
       
   624     ] ifFalse:[
       
   625         milliseconds := aTime getMilliseconds.
       
   626     ].
       
   627     ^ self getMilliseconds > milliseconds
       
   628 
       
   629     "
       
   630         (Timestamp now + 10) - Timestamp now  > 10
       
   631         (Timestamp now + 10) - Timestamp now  > 9
       
   632     "
   573 !
   633 !
   574 
   634 
   575 hash
   635 hash
   576     "return an integer useful for hashing on times"
   636     "return an integer useful for hashing on times"
   577 
   637 
   587 
   647 
   588     |todayTimestamp|
   648     |todayTimestamp|
   589 
   649 
   590     todayTimestamp := Timestamp now.
   650     todayTimestamp := Timestamp now.
   591     todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day
   651     todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day
   592 		   hour:(self hours) minute:(self minutes) second:(self seconds)
   652                    hour:(self hours) minute:(self minutes) second:(self seconds)
   593 		   millisecond:(self milliseconds).
   653                    millisecond:(self milliseconds).
   594 
   654 
   595     ^ todayTimestamp.
   655     ^ todayTimestamp.
   596 
   656 
   597     "
   657     "
   598       Time now asLocalTimestamp
   658       Time now asLocalTimestamp
   599     "
       
   600 !
       
   601 
       
   602 asMilliseconds
       
   603     "return the number of milliseconds elapsed since midnight"
       
   604 
       
   605     ^ self getMilliseconds
       
   606 
       
   607     "
       
   608      Time now asMilliSeconds
       
   609      (TimeDuration days:1) asMilliSeconds
       
   610      (TimeDuration hours:1) asMilliSeconds
       
   611     "
       
   612 
       
   613     "Created: / 05-09-2011 / 10:40:15 / cg"
       
   614 !
       
   615 
       
   616 asSeconds
       
   617     "return the number of seconds elapsed since midnight"
       
   618 
       
   619     ^ self getSeconds
       
   620 
       
   621     "
       
   622      Time now asSeconds
       
   623      (TimeDuration days:1) asSeconds
       
   624     "
   659     "
   625 !
   660 !
   626 
   661 
   627 asTime
   662 asTime
   628     "return a Time object from the receiver - that's the receiver."
   663     "return a Time object from the receiver - that's the receiver."
   915 
   950 
   916 
   951 
   917 !Time class methodsFor:'documentation'!
   952 !Time class methodsFor:'documentation'!
   918 
   953 
   919 version
   954 version
   920     ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.100 2014-11-26 09:49:45 cg Exp $'
   955     ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.101 2014-11-27 10:08:43 stefan Exp $'
   921 !
   956 !
   922 
   957 
   923 version_CVS
   958 version_CVS
   924     ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.100 2014-11-26 09:49:45 cg Exp $'
   959     ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.101 2014-11-27 10:08:43 stefan Exp $'
   925 ! !
   960 ! !
   926 
   961