AbstractTime.st
changeset 22836 1c878b36a068
parent 22826 ec2526db594c
child 22838 5e61e62bd48a
equal deleted inserted replaced
22835:157b20cb8547 22836:1c878b36a068
   260     |osTime millis micros|
   260     |osTime millis micros|
   261 
   261 
   262     osTime := OperatingSystem getOSTimeWithMicros.
   262     osTime := OperatingSystem getOSTimeWithMicros.
   263     millis := osTime at:1.
   263     millis := osTime at:1.
   264     micros := osTime at:2.
   264     micros := osTime at:2.
   265     ^ self basicNew fromOSTimeWithMilliseconds:millis picoseconds:(micros*(1000*1000)).
   265     ^ self basicNew fromOSTimeWithMilliseconds:millis additionalPicoseconds:(micros*(1000*1000)).
   266 
   266 
   267     "
   267     "
   268      Timestamp now   
   268      Timestamp now   
   269      Time now
   269      Time now
   270      Timestamp nowWithMilliseconds
   270      Timestamp nowWithMilliseconds
       
   271      Timestamp nowWithMicroseconds
   271     "
   272     "
   272 
   273 
   273     "Modified: 1.7.1996 / 15:20:10 / cg"
   274     "Modified: 1.7.1996 / 15:20:10 / cg"
   274 !
   275 !
   275 
   276 
   669 !
   670 !
   670 
   671 
   671 microseconds
   672 microseconds
   672     "return the microseconds within the current second (0..999999)"
   673     "return the microseconds within the current second (0..999999)"
   673 
   674 
   674     ^ (self milliseconds * 1000) + (self picoseconds // (1000*1000)).
   675     ^ (self milliseconds * 1000) + (self additionalPicoseconds // (1000*1000)).
   675 
   676 
   676     "
   677     "
   677      Timestamp now microseconds   
   678      Timestamp now microseconds   
   678      Timestamp nowWithMicroseconds microseconds   
   679      Timestamp nowWithMicroseconds microseconds   
   679     "
   680     "
   689      Time now minuteInDay 
   690      Time now minuteInDay 
   690     "
   691     "
   691 !
   692 !
   692 
   693 
   693 picoseconds
   694 picoseconds
   694     "return the additional picoseconds within the current second (0..999999999).
   695     "return the picoseconds within the current second (0..999999999).
   695      Here, assume that we have none"
   696      notice: that is NOT the total number of picoseconds,
   696 
   697      but the fractional part (within the second) only. 
   697     ^ 0.
   698      Use this only for printing.
       
   699      Here, fall back and generate something based on the milliseconds"
       
   700 
       
   701     ^ self milliseconds * 1000 * 1000 * 1000.
   698 
   702 
   699     "
   703     "
   700      Timestamp now picoseconds
   704      Timestamp now picoseconds
       
   705      Timestamp nowWithMicroseconds picoseconds
   701     "
   706     "
   702 !
   707 !
   703 
   708 
   704 secondInDay
   709 secondInDay
   705     "return the seconds (0..59)"
   710     "return the seconds (0..59)"
  1098 
  1103 
  1099     ^ self subclassResponsibility
  1104     ^ self subclassResponsibility
  1100 !
  1105 !
  1101 
  1106 
  1102 asMilliseconds
  1107 asMilliseconds
  1103     "return the number of milliseconds elapsed since midnight"
  1108     "return the number of milliseconds elapsed since some starttime,
       
  1109      which is subclass specific (i.e. Time: since midnight; Timestamp: since the epoch).
       
  1110      Use this only to compute relative millisecond deltas."
  1104 
  1111 
  1105     ^ self getMilliseconds
  1112     ^ self getMilliseconds
  1106 
  1113 
  1107     "
  1114     "
  1108      Time now asMilliseconds
  1115      Time now asMilliseconds
  1590     "
  1597     "
  1591 
  1598 
  1592     "Modified: 22.2.1996 / 16:58:30 / cg"
  1599     "Modified: 22.2.1996 / 16:58:30 / cg"
  1593 !
  1600 !
  1594 
  1601 
  1595 printStringIso8601Format
  1602 printStringIso8601
  1596     "return the Iso8601 representation of the receiver with local timezon information.
  1603     "return the Iso8601 representation of the receiver with local timezon information.
  1597      This format looks like:
  1604      This format looks like:
  1598 	1999-01-01T24:00:00
  1605         1999-01-01T24:00:00
  1599      or, for zero hr:min:sec,
  1606      or, for zero hr:min:sec,
  1600 	1999-01-01
  1607         1999-01-01
  1601      Of course, a 24 hour clock is used."
  1608      Of course, a 24 hour clock is used."
  1602 
  1609 
  1603     ^ String streamContents:[:s | self printIso8601FormatOn:s]
  1610     ^ String streamContents:[:s | self printIso8601FormatOn:s]
  1604 
  1611 
  1605     "
  1612     "
  1606      Timestamp now printStringIso8601Format
  1613      Timestamp now printStringIso8601Format
  1607     "
  1614     "
       
  1615 !
       
  1616 
       
  1617 printStringIso8601Format
       
  1618     <resource: #obsolete>
       
  1619 
       
  1620     "return the Iso8601 representation of the receiver with local timezon information.
       
  1621      This format looks like:
       
  1622         1999-01-01T24:00:00
       
  1623      or, for zero hr:min:sec,
       
  1624         1999-01-01
       
  1625      Of course, a 24 hour clock is used."
       
  1626 
       
  1627     self obsoleteMethodWarning:'use printStringIso8601'.
       
  1628     ^ self printStringIso8601
       
  1629 
       
  1630     "
       
  1631      Timestamp now printStringIso8601Format
       
  1632     "
  1608 ! !
  1633 ! !
  1609 
  1634 
  1610 !AbstractTime methodsFor:'private'!
  1635 !AbstractTime methodsFor:'private'!
       
  1636 
       
  1637 additionalPicoseconds
       
  1638     "return the additional picoseconds within the current second (0..999999999).
       
  1639      Here, assume that we have none"
       
  1640 
       
  1641     ^ 0.
       
  1642 
       
  1643     "
       
  1644      Timestamp now picoseconds
       
  1645     "
       
  1646 !
  1611 
  1647 
  1612 fromOSTime:osTime
  1648 fromOSTime:osTime
  1613     "set my time, from operatingSystems time parts"
  1649     "set my time, from operatingSystems time parts"
  1614 
  1650 
  1615     ^ self subclassResponsibility
  1651     ^ self subclassResponsibility
  1617     "Modified: 1.7.1996 / 15:09:44 / cg"
  1653     "Modified: 1.7.1996 / 15:09:44 / cg"
  1618 !
  1654 !
  1619 
  1655 
  1620 fromOSTimeWithMilliseconds:anUninterpretedOSTime
  1656 fromOSTimeWithMilliseconds:anUninterpretedOSTime
  1621     "strictly private: set the milliseconds from an OS time (since the epoch)"
  1657     "strictly private: set the milliseconds from an OS time (since the epoch)"
       
  1658 
       
  1659     self subclassResponsibility
       
  1660 !
       
  1661 
       
  1662 fromOSTimeWithMilliseconds:anUninterpretedOSTime additionalPicoseconds:picos
       
  1663     "strictly private: set the milliseconds from an OS time (since the epoch) plus picoSeconds"
  1622 
  1664 
  1623     self subclassResponsibility
  1665     self subclassResponsibility
  1624 !
  1666 !
  1625 
  1667 
  1626 fromOSTimeWithMilliseconds:anUninterpretedOSTime picoseconds:picos
  1668 fromOSTimeWithMilliseconds:anUninterpretedOSTime picoseconds:picos
  1630 !
  1672 !
  1631 
  1673 
  1632 getMilliseconds
  1674 getMilliseconds
  1633     "get the milliseconds since some point of time in the past.
  1675     "get the milliseconds since some point of time in the past.
  1634      Since I am abstract (not knowing how the time is actually
  1676      Since I am abstract (not knowing how the time is actually
  1635      represented), this must be done by a concrete class."
  1677      represented), this must be done by a concrete class.
       
  1678      Also be aware that the returned value is concrete-class specific;
       
  1679      Time returns the millis since midnight, Timestamp since the epoch.
       
  1680      Use this only to compute relative time deltas."
  1636 
  1681 
  1637     ^ self subclassResponsibility
  1682     ^ self subclassResponsibility
  1638 
  1683 
  1639     "Created: 1.7.1996 / 14:16:49 / cg"
  1684     "Created: 1.7.1996 / 14:16:49 / cg"
  1640 !
  1685 !