Time.st
author Claus Gittinger <cg@exept.de>
Fri, 02 Aug 2002 19:27:04 +0200
changeset 6707 790fc577c403
parent 6624 886265eff14c
child 6873 c70b04265d33
permissions -rw-r--r--
button labels uppercase
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    13
"{ Package: 'stx:libbasic' }"
5390
5a7c0581cfce comment changes
Claus Gittinger <cg@exept.de>
parents: 4999
diff changeset
    14
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    15
AbstractTime subclass:#Time
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    16
	instanceVariableNames:'timeEncoding'
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    17
	classVariableNames:''
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    18
	poolDictionaries:''
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    19
	category:'Magnitude-General'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    22
!Time class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1989 by Claus Gittinger
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    27
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
    Instances of time represent a particular time-of-day.
409
claus
parents: 394
diff changeset
    41
    Since they only store hours, minutes and seconds within a day,
claus
parents: 394
diff changeset
    42
    they cannot be used to compare times across midnight 
claus
parents: 394
diff changeset
    43
    (i.e. they should not be used as timeStamps).
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    44
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    45
    Use instances of AbsoluteTime (and read the comment there) to do this.
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    46
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    47
    Examples:
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    48
        |t|
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    49
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    50
        t := Time now.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1302
diff changeset
    51
        Transcript showCR:t.
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    52
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    53
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    54
        |t1 t2|
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    55
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    56
        t1 := Time now.
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    57
        (Delay forSeconds:10) wait.
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    58
        t2 := Time now.
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    59
        t2 - t1   
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    60
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    61
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    62
        Claus Gittinger
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    63
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    64
    [see also:]
1302
b39a598b0937 documentation
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
    65
        Date AbsoluteTime AbstractTime OperatingSystem
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    66
        Filename
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    67
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    68
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    70
!Time class methodsFor:'instance creation'!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    71
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    72
fromSeconds:secondsSinceMidnight
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    73
    "return a new Time, which represents the number of seconds since midNight.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    74
     Be careful, time wraps - if the number of seconds exceeds the number of seconds
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    75
     in a day, a time relative to another days midnight is returned.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    76
     (i.e. (Time fromSeconds:0) = (Time fromSeconds:24*3600)"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    77
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    78
    |s|
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    79
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    80
    s := secondsSinceMidnight \\ (3600 * 24).
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    81
    ^ self
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    82
        hours:(s // 3600)
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    83
        minutes:((s \\ 3600) // 60)
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    84
        seconds:((s \\ 3600) \\ 60)
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    85
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    86
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    87
     Time fromSeconds:0     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    88
     Time fromSeconds:3675     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    89
     Time fromSeconds:36000     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    90
     Time fromSeconds:72000     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    91
     Time fromSeconds:96000      
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
    92
     Time fromSeconds:360000      
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    93
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    94
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    95
    "Modified: 8.10.1996 / 19:32:11 / cg"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    96
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    97
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    98
hour:h minutes:m seconds:s
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    99
    "return an instance of Time representing the given time.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   100
     See also Time now / Date today / AbsoluteTime now.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   101
     Obsolete: please use #hours:minutes:seconds:"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   102
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   103
    <resource:#obsolete>
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   104
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   105
    self obsoleteMethodWarning:'use hours:minutes:seconds:'.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   106
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   107
    ^ self hours:h minutes:m seconds:s
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   108
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   109
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   110
     Time hours:2 minutes:33 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   111
     Time hours:0 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   112
     Time hours:24 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   113
     Time hours23 minutes:59 seconds:59 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   114
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   115
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   116
    "Modified: 19.4.1996 / 15:32:40 / cg"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   117
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   118
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   119
hours:h minutes:m seconds:s
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   120
    "return an instance of Time representing the given time.
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   121
     See also Time now / Date today / AbsoluteTime now."
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   122
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   123
    ^ self basicNew setHours:h minutes:m seconds:s
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   124
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   125
    "
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   126
     Time hours:2 minutes:33 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   127
     Time hours:0 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   128
     Time hours:24 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   129
     Time hours:23 minutes:59 seconds:59 
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   130
    "
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   131
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   132
    "Modified: 19.4.1996 / 15:32:40 / cg"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   133
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   134
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   135
readFrom:aStringOrStream onError:exceptionBlock
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   136
    "return a new Time, reading a printed representation from aStream.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   137
     If no am/pm follows the time, the string is interpreted as 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   138
     either 24 hour format or being am."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   139
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   140
    ^ [
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   141
        |str hour min sec|
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   142
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   143
        str := aStringOrStream readStream.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   144
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   145
        hour := Integer readFrom:str.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   146
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   147
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   148
        min := 0.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   149
        sec := 0.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   150
        str atEnd ifFalse:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   151
            (str peek == $:) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   152
                str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   153
                min := Integer readFrom:str.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   154
                (min between:0 and:59) ifFalse:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   155
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   156
                (str peek == $:) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   157
                    str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   158
                    sec := Integer readFrom:str.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   159
                    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   160
                ].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   161
            ].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   162
            [str peek == Character space] whileTrue:[str next].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   163
            (str peek == $p or:[str peek == $P]) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   164
                str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   165
                (str peek == $m or:[str peek == $M]) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   166
                    str next
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   167
                ].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   168
                (hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   169
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   170
                "pm"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   171
                hour ~~ 12 ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   172
                    hour := hour + 12
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   173
                ]
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   174
            ] ifFalse:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   175
                (str peek == $a or:[str peek == $A]) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   176
                    str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   177
                    (str peek == $m or:[str peek == $M]) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   178
                        str next
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   179
                    ].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   180
                    hour >= 12 ifTrue:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   181
                    hour == 24 ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   182
                        hour := 0.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   183
                    ]
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   184
                ]
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   185
            ]
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   186
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   187
        self basicNew setHours:hour minutes:min seconds:sec
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   188
    ] on:Error do:exceptionBlock.
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   189
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   190
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   191
     Time readFrom:'0:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   192
     Time readFrom:'2:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   193
     Time readFrom:'12:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   194
     Time readFrom:'14:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   195
     Time readFrom:'23:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   196
     Time readFrom:'24:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   197
     Time readFrom:'2:30 am'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   198
     Time readFrom:'2:30 pm'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   199
     Time readFrom:'14'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   200
     Time readFrom:'2 am'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   201
     Time readFrom:'2 pm'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   202
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   203
     Time readFrom:'18:22:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   204
     Time readFrom:'14:00:11'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   205
     Time readFrom:'7:00:11'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   206
     Time readFrom:'24:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   207
     Time readFrom:'0:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   208
     Time readFrom:'12:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   209
     Time readFrom:'0:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   210
     Time readFrom:'6:22:00 pm'   
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   211
     Time readFrom:'2:00:11 pm'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   212
     Time readFrom:'7:00:11 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   213
     Time readFrom:'12:00:00 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   214
     Time readFrom:'0:00:00 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   215
     Time readFrom:'24:00:00 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   216
     Time readFrom:'12:00:00 pm'  
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   217
     Time readFrom:'0:00:00 pm' onError:'invalid'
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   218
     Time readFrom:'24:00:00 pm'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   219
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   220
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   221
    "Modified: 8.10.1996 / 19:32:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   222
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   224
!Time class methodsFor:'format strings'!
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   225
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   226
formatString12us
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   227
    "return the format string used to format US times (and other areas)"
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   228
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   229
    ^ '%u:%m:%s %a'
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   230
!
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   231
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   232
formatString24
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   233
    "return the format string used to format european times (and other areas)"
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   234
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   235
    ^ '%h:%m:%s'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   236
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   237
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   238
!Time methodsFor:'Compatibility - Squeak'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   239
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   240
intervalString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   241
    "Treat the time as a difference.  
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   242
     Give it in hours and minutes with two digits of accuracy."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   243
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   244
    |hours minutes seconds hh mm ss s|
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   245
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   246
    hours := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   247
    minutes := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   248
    seconds := self seconds.
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   249
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   250
    hours = 0   
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   251
        ifTrue: [hh := ''] 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   252
        ifFalse: [
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   253
            hh := hours printString, ' hour'.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   254
            hours > 1 ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   255
                hh := hh , 's'
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   256
            ]
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   257
        ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   258
    minutes = 0 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   259
        ifTrue: [mm := ''] 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   260
        ifFalse: [
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   261
            mm := minutes printString, ' minute'.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   262
            minutes > 1 ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   263
                mm := mm , 's'
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   264
            ]
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   265
        ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   266
    seconds = 0 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   267
        ifTrue: [ss := ''] 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   268
        ifFalse: [
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   269
            ss := seconds printString, ' second'.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   270
            seconds > 1 ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   271
                ss := ss , 's'
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   272
            ]
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   273
        ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   274
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   275
    "/ do not show seconds, if hours are there
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   276
    hh size > 0 ifTrue: [ss := ''].
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   277
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   278
    s := hh.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   279
    hh notEmpty ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   280
        hh := hh , ' '
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   281
    ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   282
    s := s , mm.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   283
    mm notEmpty ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   284
        mm := mm , ' '
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   285
    ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   286
    ^ s , ss
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   287
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   288
    "
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   289
     (Time fromSeconds:360000) intervalString      
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   290
     (Time fromSeconds:3600) intervalString    
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   291
     (Time fromSeconds:3605) intervalString  
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   292
     (Time fromSeconds:3700) intervalString  
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   293
     (Time fromSeconds:5) intervalString    
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   294
     (Time fromSeconds:65) intervalString   
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   295
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   296
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   297
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   298
print24:prnt24Format showSeconds:doSeconds on:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   299
    "print me either US or 24hr format, optionally with
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   300
     seconds on a stream"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   301
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   302
    |format|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   303
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   304
    prnt24Format ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   305
        doSeconds ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   306
            format := '%h:%m:%s'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   307
        ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   308
            format := '%h:%m'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   309
        ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   310
    ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   311
        "/ US format
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   312
        doSeconds ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   313
            format := '%u:%m:%s %a'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   314
        ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   315
            format := '%u:%m %a'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   316
        ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   317
    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   318
    ^ self
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   319
        printOn:aStream 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   320
        format:format.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   321
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   322
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   323
     Time now print24:true showSeconds:true on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   324
     Time now print24:false showSeconds:true on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   325
     Time now print24:true showSeconds:false on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   326
     Time now print24:false showSeconds:false on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   327
    "
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   328
! !
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   329
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   330
!Time methodsFor:'accessing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   331
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   332
day
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   333
    "catch day access - Time does not know about it"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   334
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   335
    ^ self shouldNotImplement
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   336
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   337
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   338
hours
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   339
    "return the number of hours since midnight (i.e. 0..23)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   340
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   341
    ^ self getSeconds // 3600
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   342
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   343
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   344
     Time now hours
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   345
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   346
!
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   347
4845
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   348
milliseconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   349
    "time does not keep milliseconds 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   350
     - for compatibility with absoluteTime"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   351
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   352
    ^ 0
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   353
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   354
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   355
minutes
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   356
    "return the number of minutes within the hour (i.e. 0..59)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   357
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   358
    ^ (self getSeconds \\ 3600) // 60
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   359
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   360
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   361
     Time now minutes
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   362
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   363
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   364
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   365
month 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   366
    "catch month access - Time does not know about it"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   367
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   368
    ^ self shouldNotImplement
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   369
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   370
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   371
seconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   372
    "return the number of seconds within the minute (i.e. 0..59)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   373
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   374
    ^ (self getSeconds \\ 3600) \\ 60
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   375
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   376
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   377
     Time now seconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   378
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   379
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   380
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   381
year
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   382
    "catch year access - Time does not know about it"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   383
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   384
    ^ self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   387
!Time methodsFor:'comparing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   388
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   389
< aTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   390
    "return true if the receiver is before the argument"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   391
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   392
    ^ self getSeconds < aTime getSeconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   393
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   394
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   395
= aTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   396
    "return true if the argument, aTime represents the same timeOfDay"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   397
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   398
    aTime class == self class ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   399
        ^ timeEncoding == aTime timeEncoding
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   400
    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   401
    (aTime species == self species) ifFalse:[^ false].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   402
    ^ self getSeconds == aTime getSeconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   403
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   404
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   405
> aTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   406
    "return true if the receiver is before the argument"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   407
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   408
    ^ self getSeconds > aTime getSeconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   409
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   410
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   411
hash
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   412
    "return an integer useful for hashing on times"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   413
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   414
    ^ self getSeconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   415
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   416
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   417
!Time methodsFor:'converting'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   418
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   419
asAbsoluteTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   420
    "return an AbsoluteTime object from the receiver.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   421
     The date components are taken from today."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   422
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   423
    |today|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   424
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   425
    today := Date today.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   426
    ^ AbsoluteTime year:today year month:today month day:today day
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   427
                   hour:(self hours) minute:(self minutes) second:(self seconds)
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   428
                   millisecond:(self milliseconds)
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   429
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   430
     Time now asAbsoluteTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   431
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   432
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   433
    "Modified: / 13.7.1999 / 12:32:08 / stefan"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   434
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   435
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   436
asSeconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   437
    "return the number of seconds elapsed since midnight"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   438
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   439
    ^ self getSeconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   440
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   441
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   442
     Time now asSeconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   443
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   444
!
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   445
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   446
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   447
    "return a Time object from the receiver - thats the receiver."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   448
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   449
    ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   450
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   451
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   452
!Time methodsFor:'printing & storing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   453
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   454
print12HourFormatOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   455
    "append a printed representation of the receiver to aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   456
     Format is hh:mm:ss am/pm (i.e. 12-hour american format)."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   457
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   458
    ^ self
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   459
        printOn:aStream 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   460
        format:(self class formatString12us)
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   461
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   462
"/    |h m s ampm|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   463
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   464
"/    h := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   465
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   466
"/    "/ 0 -> 12 am
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   467
"/    "/ 12 -> 12 pm
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   468
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   469
"/    h // 12 == 0 ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   470
"/        ampm := ' am'.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   471
"/    ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   472
"/        ampm := ' pm'.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   473
"/    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   474
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   475
"/    h == 0 ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   476
"/        h := h - 1 \\ 12 + 1.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   477
"/    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   478
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   479
"/    h printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   480
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   481
"/    m := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   482
"/    (m < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   483
"/    m printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   484
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   485
"/    s := self seconds.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   486
"/    (s < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   487
"/    s printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   488
"/    aStream nextPutAll:ampm
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   489
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   490
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   491
     Time now print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   492
     (Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   493
     (Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   494
     (Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   495
     (Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   496
     0 to:24 do:[:h |
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   497
         (Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   498
     ]
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   499
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   500
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   501
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   502
print24HourFormatOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   503
    "append a printed representation of the receiver to aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   504
     Format is hh:mm:ss (i.e. 24-hour european format)."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   505
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   506
    ^ self
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   507
        printOn:aStream 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   508
        format:(self class formatString24).
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   509
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   510
"/    |h m s|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   511
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   512
"/    h := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   513
"/    (h < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   514
"/    h printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   515
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   516
"/    m := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   517
"/    (m < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   518
"/    m printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   519
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   520
"/    s := self seconds.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   521
"/    (s < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   522
"/    s printOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   523
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   524
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   525
     Time now print24HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   526
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   527
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   528
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   529
printOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   530
    "append a user printed representation of the receiver to aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   531
     The format is suitable for a human - not meant to be read back.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   532
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   533
     Format is hh:mm:ss either in 12-hour or 24-hour format.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   534
     depending on the setting of LanguageTerritory.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   535
     I dont know what ST-80 does here (12-hour format ?)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   536
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   537
    LanguageTerritory == #us ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   538
        self print12HourFormatOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   539
    ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   540
        self print24HourFormatOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   541
    ]
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   542
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   543
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   544
     Time now printOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   545
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   546
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   547
    "Modified: 22.2.1996 / 16:58:30 / cg"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   548
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   549
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   550
printString12HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   551
    "return a printed representation in 12 hour format"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   552
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   553
    ^ self printStringFormat:(self class formatString12us)               
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   554
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   555
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   556
     Time now printString12HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   557
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   558
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   559
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   560
printString24HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   561
    "return a printed representation in 24 hour format"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   562
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   563
    ^ self printStringFormat:(self class formatString24)               
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   564
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   565
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   566
     Time now printString24HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   567
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   568
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   569
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   570
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   571
shortPrintString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   572
    "dummy - for now"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   573
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   574
    ^ self printString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   575
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   576
    "Created: 20.6.1997 / 17:17:01 / cg"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   577
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   578
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   579
!Time methodsFor:'private'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   580
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   581
fromOSTime:osTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   582
    "set my time, given an osTime"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   583
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   584
    |h m s|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   585
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   586
    OperatingSystem computeTimePartsOf:osTime for:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   587
        :hours :minutes :secs :millis |
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   588
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   589
        h := hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   590
        m := minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   591
        s := secs.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   592
    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   593
    self setHours:h minutes:m seconds:s
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   594
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   595
    "Modified: 1.7.1996 / 15:21:06 / cg"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   596
!
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   597
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   598
getMilliseconds
6046
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   599
    "return the number of milliseconds since midnight"
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   600
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   601
    ^ self getSeconds * 1000
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   602
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   603
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   604
getSeconds
6046
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   605
    "return the number of seconds since midnight"
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   606
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   607
    ^ timeEncoding
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   608
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   609
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   610
setHours:h minutes:m seconds:s
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   611
    "set my time given individual values"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   612
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   613
    self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s).
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   614
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   615
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   616
setMilliseconds:millis
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   617
    "set my time given milliseconds since midnight"
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   618
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   619
    self setSeconds:(millis // 1000)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   620
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   621
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   622
setSeconds:secs
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   623
    "set my time given seconds since midnight"
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   624
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   625
    secs < 0 ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   626
        timeEncoding := (24 * 3600) - (secs negated \\ (24 * 3600))
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   627
    ] ifFalse:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   628
        timeEncoding := secs
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   629
    ].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   630
    timeEncoding > (24 * 3600) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   631
        timeEncoding := timeEncoding \\ (24 * 3600).
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   632
    ]
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   633
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   634
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   635
     Time now seconds
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   636
     Time now timeEncoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   637
     (Time now addDays:5) seconds     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   638
     (Time now addDays:5) timeEncoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   639
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   640
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   641
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   642
timeEncoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   643
    "the internal encoding is stricktly private, 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   644
     and should not be used outside."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   645
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   646
    ^ timeEncoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   647
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   648
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   649
timeEncoding:encoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   650
    "the internal encoding is stricktly private, 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   651
     and should not be used outside."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   652
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   653
    timeEncoding := encoding
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   654
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   655
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   656
!Time class methodsFor:'documentation'!
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   657
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   658
version
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   659
    ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.54 2002-07-15 09:24:11 stefan Exp $'
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   660
! !