Time.st
author Claus Gittinger <cg@exept.de>
Fri, 07 Sep 2001 13:14:21 +0200
changeset 5982 2965b58b4258
parent 5873 1ed3dd2e1b17
child 6045 c2b7455fcdfe
permissions -rw-r--r--
ANSI accessors
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
159
514c749165c3 *** empty log message ***
claus
parents: 95
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
5390
5a7c0581cfce comment changes
Claus Gittinger <cg@exept.de>
parents: 4999
diff changeset
    13
"{ Package: 'stx:libbasic' }"
5a7c0581cfce comment changes
Claus Gittinger <cg@exept.de>
parents: 4999
diff changeset
    14
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
    15
AbstractTime subclass:#Time
993
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    16
	instanceVariableNames:'timeEncoding'
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    17
	classVariableNames:''
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    18
	poolDictionaries:''
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
    19
	category:'Magnitude-General'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
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
159
514c749165c3 *** empty log message ***
claus
parents: 95
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
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
    70
!Time class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    72
fromSeconds:secondsSinceMidnight
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    73
    "return a new Time, which represents the number of seconds since midNight.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    74
     Be careful, time wraps - if the number of seconds exceeds the number of seconds
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    75
     in a day, a time relative to another days midnight is returned.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    76
     (i.e. (Time fromSeconds:0) = (Time fromSeconds:24*3600)"
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    77
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    78
    |s|
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    79
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    80
    s := secondsSinceMidnight \\ (3600 * 24).
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    81
    ^ self
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    82
        hours:(s // 3600)
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    83
        minutes:((s \\ 3600) // 60)
4883
39898c714eb6 bugfix fromSeconds: (prev. version add 1 hour)
ah
parents: 4845
diff changeset
    84
        seconds:((s \\ 3600) \\ 60)
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    85
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    86
    "
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    87
     Time fromSeconds:0     
4883
39898c714eb6 bugfix fromSeconds: (prev. version add 1 hour)
ah
parents: 4845
diff changeset
    88
     Time fromSeconds:3675     
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    89
     Time fromSeconds:36000     
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    90
     Time fromSeconds:72000     
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    91
     Time fromSeconds:96000      
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    92
    "
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    93
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    94
    "Modified: 8.10.1996 / 19:32:11 / cg"
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    95
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    96
4883
39898c714eb6 bugfix fromSeconds: (prev. version add 1 hour)
ah
parents: 4845
diff changeset
    97
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    98
!
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
    99
239
472f810ecccf readFrom; houtr:minutes:seconds: fixed
claus
parents: 216
diff changeset
   100
hour:h minutes:m seconds:s
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
   101
    "return an instance of Time representing the given time.
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   102
     See also Time now / Date today / AbsoluteTime now.
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   103
     Obsolete: please use #hours:minutes:seconds:"
239
472f810ecccf readFrom; houtr:minutes:seconds: fixed
claus
parents: 216
diff changeset
   104
5873
1ed3dd2e1b17 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5390
diff changeset
   105
    <resource:#obsolete>
1ed3dd2e1b17 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5390
diff changeset
   106
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   107
    self obsoleteMethodWarning:'use hours:minutes:seconds:'.
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   108
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   109
    ^ self hours:h minutes:m seconds:s
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   110
239
472f810ecccf readFrom; houtr:minutes:seconds: fixed
claus
parents: 216
diff changeset
   111
    "
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   112
     Time hours:2 minutes:33 seconds:0 
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   113
     Time hours:0 minutes:0 seconds:0 
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   114
     Time hours:24 minutes:0 seconds:0 
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   115
     Time hours23 minutes:59 seconds:59 
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   116
    "
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   117
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   118
    "Modified: 19.4.1996 / 15:32:40 / cg"
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   119
!
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   120
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   121
hours:h minutes:m seconds:s
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   122
    "return an instance of Time representing the given time.
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   123
     See also Time now / Date today / AbsoluteTime now."
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
    ^ self basicNew setHours:h minutes:m seconds:s
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   126
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   127
    "
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   128
     Time hours:2 minutes:33 seconds:0 
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   129
     Time hours:0 minutes:0 seconds:0 
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   130
     Time hours:24 minutes:0 seconds:0 
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   131
     Time hours:23 minutes:59 seconds:59 
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   132
    "
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
   133
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
   134
    "Modified: 19.4.1996 / 15:32:40 / cg"
77
6c38ca59927f *** empty log message ***
claus
parents: 62
diff changeset
   135
!
6c38ca59927f *** empty log message ***
claus
parents: 62
diff changeset
   136
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   137
readFrom:aStringOrStream onError:exceptionBlock
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   138
    "return a new Time, reading a printed representation from aStream.
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   139
     If no am/pm follows the time, the string is interpreted as 
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   140
     either 24 hour format or being am."
239
472f810ecccf readFrom; houtr:minutes:seconds: fixed
claus
parents: 216
diff changeset
   141
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   142
    |newTime|
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   143
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1502
diff changeset
   144
    ErrorSignal handle:[:ex |
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1502
diff changeset
   145
        ^ exceptionBlock value
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1502
diff changeset
   146
    ] do:[
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   147
        |str hour min sec|
216
a8abff749575 *** empty log message ***
claus
parents: 159
diff changeset
   148
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1502
diff changeset
   149
        str := aStringOrStream readStream.
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1502
diff changeset
   150
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   151
        hour := Integer readFrom:str.
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   152
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   153
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   154
        min := 0.
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   155
        sec := 0.
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   156
        str atEnd ifFalse:[
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   157
            (str peek == $:) ifTrue:[
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   158
                str next.
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   159
                min := Integer readFrom:str.
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   160
                (min between:0 and:59) ifFalse:[^ exceptionBlock value].
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   161
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   162
                (str peek == $:) ifTrue:[
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   163
                    str next.
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   164
                    sec := Integer readFrom:str.
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   165
                    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   166
                ].
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   167
            ].
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   168
            [str peek == Character space] whileTrue:[str next].
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   169
            (str peek == $p or:[str peek == $P]) ifTrue:[
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   170
                str next.
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   171
                (str peek == $m or:[str peek == $M]) ifTrue:[
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   172
                    str next
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   173
                ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   174
                (hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value].
3478
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   175
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   176
                "pm"
3478
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   177
                hour ~~ 12 ifTrue:[
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   178
                    hour := hour + 12
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   179
                ]
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   180
            ] ifFalse:[
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   181
                (str peek == $a or:[str peek == $A]) ifTrue:[
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   182
                    str next.
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   183
                    (str peek == $m or:[str peek == $M]) ifTrue:[
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   184
                        str next
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   185
                    ].
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   186
                    hour >= 12 ifTrue:[^ exceptionBlock value].
3478
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   187
                    hour == 24 ifTrue:[
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   188
                        hour := 0.
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   189
                    ]
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   190
                ]
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   191
            ]
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1502
diff changeset
   192
        ].
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   193
        newTime := self basicNew setHours:hour minutes:min seconds:sec
3995
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   194
    ].
777470826394 no need for another error-handler blcok in #readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 3709
diff changeset
   195
    ^ newTime
216
a8abff749575 *** empty log message ***
claus
parents: 159
diff changeset
   196
239
472f810ecccf readFrom; houtr:minutes:seconds: fixed
claus
parents: 216
diff changeset
   197
    "
3481
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   198
     Time readFrom:'0:00'     
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   199
     Time readFrom:'2:00'     
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   200
     Time readFrom:'12:00'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   201
     Time readFrom:'14:00'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   202
     Time readFrom:'23:00'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   203
     Time readFrom:'24:00'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   204
     Time readFrom:'2:30 am'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   205
     Time readFrom:'2:30 pm'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   206
     Time readFrom:'14'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   207
     Time readFrom:'2 am'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   208
     Time readFrom:'2 pm'    
1da093bda862 allow reading of times without secs/minutes.
Claus Gittinger <cg@exept.de>
parents: 3478
diff changeset
   209
409
claus
parents: 394
diff changeset
   210
     Time readFrom:'18:22:00'    
claus
parents: 394
diff changeset
   211
     Time readFrom:'14:00:11'    
claus
parents: 394
diff changeset
   212
     Time readFrom:'7:00:11'     
3478
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   213
     Time readFrom:'24:00:00'     
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   214
     Time readFrom:'0:00:00'     
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   215
     Time readFrom:'12:00:00'     
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   216
     Time readFrom:'0:00:00'     
409
claus
parents: 394
diff changeset
   217
     Time readFrom:'6:22:00 pm'   
claus
parents: 394
diff changeset
   218
     Time readFrom:'2:00:11 pm'  
claus
parents: 394
diff changeset
   219
     Time readFrom:'7:00:11 am'  
3478
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   220
     Time readFrom:'12:00:00 am'  
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   221
     Time readFrom:'0:00:00 am'  
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   222
     Time readFrom:'24:00:00 am'  
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   223
     Time readFrom:'12:00:00 pm'  
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   224
     Time readFrom:'0:00:00 pm'   - invalid
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   225
     Time readFrom:'24:00:00 pm'  
239
472f810ecccf readFrom; houtr:minutes:seconds: fixed
claus
parents: 216
diff changeset
   226
    "
569
7134eb78cf48 readFrom:onError: can now also read from a string
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
1701
80d13adb2e77 better errorHandling in readFrom:onError:
Claus Gittinger <cg@exept.de>
parents: 1502
diff changeset
   228
    "Modified: 8.10.1996 / 19:32:11 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   229
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   230
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   231
!Time class methodsFor:'format strings'!
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   232
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   233
formatString12us
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   234
    "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
   235
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   236
    ^ '%u:%m:%s %a'
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   237
!
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   238
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   239
formatString24
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   240
    "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
   241
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   242
    ^ '%h:%m:%s'
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   243
! !
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   244
4412
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   245
!Time methodsFor:'Compatibility - Squeak'!
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   246
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   247
intervalString
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   248
    "Treat the time as a difference.  
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   249
     Give it in hours and minutes with two digits of accuracy."
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   250
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   251
    |hours minutes seconds hh mm ss |
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   252
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   253
    hours := self hours.
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   254
    minutes := self minutes.
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   255
    seconds := self seconds.
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   256
    hh := hours = 0   ifTrue: [''] ifFalse: [' ', hours printString, ' hours'].
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   257
    mm := minutes = 0 ifTrue: [''] ifFalse: [' ', minutes printString, ' minutes'].
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   258
    ss := seconds = 0 ifTrue: [''] ifFalse: [' ', seconds printString, ' seconds'].
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   259
    hh size > 0 ifTrue: [ss := ''].
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   260
    ^ hh, mm, ss
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   261
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   262
    "
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   263
     (Time fromSeconds:3600) intervalString
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   264
     (Time fromSeconds:3605) intervalString
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   265
     (Time fromSeconds:5) intervalString  
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   266
     (Time fromSeconds:65) intervalString   
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   267
    "
4999
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   268
!
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   269
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   270
print24:prnt24Format showSeconds:doSeconds on:aStream
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   271
    "print me either US or 24hr format, optionally with
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   272
     seconds on a stream"
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   273
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   274
    |format|
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   275
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   276
    prnt24Format ifTrue:[
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   277
        doSeconds ifTrue:[
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   278
            format := '%h:%m:%s'
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   279
        ] ifFalse:[
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   280
            format := '%h:%m'
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   281
        ].
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   282
    ] ifFalse:[
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   283
        "/ US format
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   284
        doSeconds ifTrue:[
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   285
            format := '%u:%m:%s %a'
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   286
        ] ifFalse:[
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   287
            format := '%u:%m %a'
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   288
        ].
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   289
    ].
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   290
    ^ self
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   291
        printOn:aStream 
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   292
        format:format.
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   293
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   294
    "
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   295
     Time now print24:true showSeconds:true on:Transcript. Transcript cr.
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   296
     Time now print24:false showSeconds:true on:Transcript. Transcript cr.
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   297
     Time now print24:true showSeconds:false on:Transcript. Transcript cr.
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   298
     Time now print24:false showSeconds:false on:Transcript. Transcript cr.
9d424b34577e squeak compatible printing
Claus Gittinger <cg@exept.de>
parents: 4883
diff changeset
   299
    "
4412
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   300
! !
9d7d27246c25 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4411
diff changeset
   301
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   302
!Time methodsFor:'accessing'!
77
6c38ca59927f *** empty log message ***
claus
parents: 62
diff changeset
   303
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   304
day
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   305
    "catch day access - Time does not know about it"
77
6c38ca59927f *** empty log message ***
claus
parents: 62
diff changeset
   306
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   307
    ^ self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   308
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   309
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   310
hours
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   311
    "return the number of hours since midnight (i.e. 0..23)"
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   312
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   313
    ^ timeEncoding // 3600
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   314
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   315
    "
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   316
     Time now hours
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   317
    "
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   318
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   319
4845
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   320
milliseconds
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   321
    "time does not keep milliseconds 
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   322
     - for compatibility with absoluteTime"
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   323
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   324
    ^ 0
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   325
!
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   326
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   327
minutes
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   328
    "return the number of minutes within the hour (i.e. 0..59)"
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   329
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   330
    ^ (timeEncoding \\ 3600) // 60
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   331
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   332
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   333
     Time now minutes
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   334
    "
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   335
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   336
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   337
month 
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   338
    "catch month access - Time does not know about it"
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   339
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   340
    ^ self shouldNotImplement
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   341
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   342
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   343
seconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   344
    "return the number of seconds within the minute (i.e. 0..59)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   345
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   346
    ^ (timeEncoding \\ 3600) \\ 60
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   347
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   348
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   349
     Time now seconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   350
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   351
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   352
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   353
year
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   354
    "catch year access - Time does not know about it"
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   355
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   356
    ^ self shouldNotImplement
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   357
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   358
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   359
!Time methodsFor:'comparing'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   360
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   361
< aTime
5390
5a7c0581cfce comment changes
Claus Gittinger <cg@exept.de>
parents: 4999
diff changeset
   362
    "return true if the receiver is before the argument"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   363
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   364
    ^ timeEncoding < aTime timeEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   365
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   367
= aTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   368
    "return true if the argument, aTime represents the same timeOfDay"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   369
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   370
    aTime class == self class ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   371
	^ timeEncoding == aTime timeEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   372
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   373
    (aTime species == self species) ifFalse:[^ false].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   374
    ^ self asSeconds == aTime asSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   375
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   376
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   377
> aTime
5390
5a7c0581cfce comment changes
Claus Gittinger <cg@exept.de>
parents: 4999
diff changeset
   378
    "return true if the receiver is before the argument"
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   379
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   380
    ^ timeEncoding > aTime timeEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   381
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   382
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   383
hash
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   384
    "return an integer useful for hashing on times"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   385
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   386
    ^ timeEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   387
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   388
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   389
!Time methodsFor:'converting'!
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   390
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   391
asAbsoluteTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   392
    "return an AbsoluteTime object from the receiver.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   393
     The date components are taken from today."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   394
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   395
    |today|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   396
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   397
    today := Date today.
4379
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 4031
diff changeset
   398
    ^ AbsoluteTime year:today year month:today month day:today day
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 4031
diff changeset
   399
                   hour:self hours minute:self minutes second:self seconds
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   400
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   401
     Time now asAbsoluteTime
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   402
    "
4379
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 4031
diff changeset
   403
20ba95273826 Use more consistent spelling.
Stefan Vogel <sv@exept.de>
parents: 4031
diff changeset
   404
    "Modified: / 13.7.1999 / 12:32:08 / stefan"
62
e1b4369c61fb *** empty log message ***
claus
parents: 32
diff changeset
   405
!
e1b4369c61fb *** empty log message ***
claus
parents: 32
diff changeset
   406
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   407
asSeconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   408
    "return the number of seconds elapsed since midnight"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   409
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   410
    ^ timeEncoding
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   411
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   412
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   413
     Time now asSeconds
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   414
    "
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   415
!
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   416
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   417
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   418
    "return a Time object from the receiver - thats the receiver."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   419
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   420
    ^ self
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   421
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   422
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   423
!Time methodsFor:'printing & storing'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   424
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   425
print12HourFormatOn:aStream
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   426
    "append a printed representation of the receiver to aStream.
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   427
     Format is hh:mm:ss am/pm (i.e. 12-hour american format)."
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   428
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   429
    ^ self
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   430
        printOn:aStream 
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   431
        format:(self class formatString12us)
3478
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   432
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   433
"/    |h m s ampm|
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   434
"/
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   435
"/    h := self hours.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   436
"/
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   437
"/    "/ 0 -> 12 am
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   438
"/    "/ 12 -> 12 pm
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   439
"/
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   440
"/    h // 12 == 0 ifTrue:[
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   441
"/        ampm := ' am'.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   442
"/    ] ifFalse:[
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   443
"/        ampm := ' pm'.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   444
"/    ].
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   445
"/
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   446
"/    h == 0 ifFalse:[
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   447
"/        h := h - 1 \\ 12 + 1.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   448
"/    ].
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   449
"/
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   450
"/    h printOn:aStream.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   451
"/    aStream nextPut:$:.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   452
"/    m := self minutes.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   453
"/    (m < 10) ifTrue:[aStream nextPut:$0].
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   454
"/    m printOn:aStream.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   455
"/    aStream nextPut:$:.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   456
"/    s := self seconds.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   457
"/    (s < 10) ifTrue:[aStream nextPut:$0].
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   458
"/    s printOn:aStream.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   459
"/    aStream nextPutAll:ampm
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   460
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   461
    "
216
a8abff749575 *** empty log message ***
claus
parents: 159
diff changeset
   462
     Time now print12HourFormatOn:Transcript. Transcript cr
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   463
     (Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   464
     (Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   465
     (Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   466
     (Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
3478
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   467
     0 to:24 do:[:h |
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   468
         (Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
3f1a83b35865 12 hour format, again
Claus Gittinger <cg@exept.de>
parents: 3477
diff changeset
   469
     ]
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   470
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   471
!
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   472
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   473
print24HourFormatOn:aStream
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   474
    "append a printed representation of the receiver to aStream.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   475
     Format is hh:mm:ss (i.e. 24-hour european format)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   476
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   477
    ^ self
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   478
        printOn:aStream 
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   479
        format:(self class formatString24).
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   480
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   481
"/    |h m s|
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   482
"/
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   483
"/    h := self hours.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   484
"/    (h < 10) ifTrue:[aStream nextPut:$0].
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   485
"/    h printOn:aStream.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   486
"/    aStream nextPut:$:.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   487
"/    m := self minutes.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   488
"/    (m < 10) ifTrue:[aStream nextPut:$0].
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   489
"/    m printOn:aStream.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   490
"/    aStream nextPut:$:.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   491
"/    s := self seconds.
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   492
"/    (s < 10) ifTrue:[aStream nextPut:$0].
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   493
"/    s printOn:aStream
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   494
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   495
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   496
     Time now print24HourFormatOn:Transcript. Transcript cr
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   497
    "
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   498
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   499
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   500
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
   501
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
   502
     The format is suitable for a human - not meant to be read back.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4379
diff changeset
   503
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   504
     Format is hh:mm:ss either in 12-hour or 24-hour format.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   505
     depending on the setting of LanguageTerritory.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   506
     I dont know what ST-80 does here (12-hour format ?)"
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   507
993
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   508
    LanguageTerritory == #us ifTrue:[
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   509
        self print12HourFormatOn:aStream
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   510
    ] ifFalse:[
993
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   511
        self print24HourFormatOn:aStream
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   512
    ]
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   513
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   514
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   515
     Time now printOn:Transcript. Transcript cr
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   516
    "
993
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   517
feaa62827c41 check for territory being #us (instead of #usa) when printing
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
   518
    "Modified: 22.2.1996 / 16:58:30 / cg"
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   519
!
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   520
3709
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   521
printString12HourFormat
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   522
    "return a printed representation in 12 hour format"
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   523
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   524
    ^ self printStringFormat:(self class formatString12us)               
3709
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   525
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   526
    "
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   527
     Time now printString12HourFormat
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   528
    "
3709
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   529
!
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   530
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   531
printString24HourFormat
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   532
    "return a printed representation in 24 hour format"
74a8b2073ab1 12 + 24 hour format printStrings added
tz
parents: 3481
diff changeset
   533
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   534
    ^ self printStringFormat:(self class formatString24)               
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   535
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   536
    "
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   537
     Time now printString24HourFormat
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   538
    "
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   539
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   540
!
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   541
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   542
shortPrintString
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   543
    "dummy - for now"
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   544
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   545
    ^ self printString
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   546
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   547
    "Created: 20.6.1997 / 17:17:01 / cg"
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   548
! !
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   549
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   550
!Time methodsFor:'private'!
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   551
1502
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   552
fromOSTime:osTime
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   553
    "set my time, given an osTime"
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   554
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   555
    |h m s|
1502
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   556
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   557
    OperatingSystem computeTimePartsOf:osTime for:[
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   558
        :hours :minutes :secs :millis |
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   559
1502
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   560
        h := hours.
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   561
        m := minutes.
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   562
        s := secs.
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   563
    ].
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   564
    self setHours:h minutes:m seconds:s
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   565
1502
b334a6f69344 time changes
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   566
    "Modified: 1.7.1996 / 15:21:06 / cg"
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   567
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   568
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   569
getMilliseconds
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   570
    ^ self getSeconds * 1000
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   571
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   572
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   573
getSeconds
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   574
    ^ timeEncoding
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   575
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   576
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   577
setHours:h minutes:m seconds:s
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   578
    "set my time given individual values"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   579
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   580
    self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s).
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   581
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   582
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   583
setMilliseconds:millis
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   584
    "set my time given milliseconds since midnight"
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   585
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   586
    self setSeconds:(millis // 1000)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   587
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   588
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   589
setSeconds:secs
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   590
    "set my time given seconds since midnight"
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   591
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   592
    secs < 0 ifTrue:[
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   593
        timeEncoding := (24 * 3600) - (secs negated \\ (24 * 3600))
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   594
    ] ifFalse:[
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   595
        timeEncoding := secs
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   596
    ]
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   597
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   598
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   599
timeEncoding
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   600
    "the internal encoding is stricktly private, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   601
     and should not be used outside."
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   602
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   603
    ^ timeEncoding
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   604
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   605
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   606
timeEncoding:encoding
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   607
    "the internal encoding is stricktly private, 
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   608
     and should not be used outside."
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   609
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   610
    timeEncoding := encoding
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   611
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   612
2706
878723bc99fc added #shortPrintString for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 1701
diff changeset
   613
!Time class methodsFor:'documentation'!
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   614
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   615
version
5873
1ed3dd2e1b17 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5390
diff changeset
   616
    ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.47 2001-05-17 22:42:20 stefan Exp $'
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   617
! !