Time.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 19 Jan 2012 11:46:00 +0000
branchjv
changeset 17911 a99f15c5efa5
parent 17910 8d796ca8bd1d
child 18011 deb0c3355881
permissions -rw-r--r--
Updated with /trunk
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
"
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    12
"{ Package: 'stx:libbasic' }"
5390
5a7c0581cfce comment changes
Claus Gittinger <cg@exept.de>
parents: 4999
diff changeset
    13
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    14
AbstractTime subclass:#Time
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    15
	instanceVariableNames:'timeEncoding'
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    16
	classVariableNames:''
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    17
	poolDictionaries:''
7672
46f206594db3 Category change
Stefan Vogel <sv@exept.de>
parents: 7513
diff changeset
    18
	category:'Magnitude-Time'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    21
!Time class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    26
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
"
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
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
    Instances of time represent a particular time-of-day.
409
claus
parents: 394
diff changeset
    40
    Since they only store hours, minutes and seconds within a day,
claus
parents: 394
diff changeset
    41
    they cannot be used to compare times across midnight 
claus
parents: 394
diff changeset
    42
    (i.e. they should not be used as timeStamps).
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    43
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
    44
    Use instances of Timestamp (and read the comment there) to do this.
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    45
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
    46
    Time now returns the time in the local timezone.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
    47
    Use Time utcNow to get the time in the UTC zone.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
    48
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    49
    Examples:
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    50
        |t|
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    51
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    52
        t := Time now.
1422
9a0b792f2953 showCr: -> showCR:
Claus Gittinger <cg@exept.de>
parents: 1302
diff changeset
    53
        Transcript showCR:t.
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    54
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    55
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    56
        |t1 t2|
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    57
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    58
        t1 := Time now.
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    59
        (Delay forSeconds:10) wait.
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    60
        t2 := Time now.
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    61
        t2 - t1   
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    62
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    63
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    64
        Claus Gittinger
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    65
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    66
    [see also:]
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
    67
        Date Timestamp AbstractTime OperatingSystem
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    68
        Filename
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    69
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    70
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    72
!Time class methodsFor:'instance creation'!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    73
17850
8fa257692c35 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
    74
fromString: aString
8fa257692c35 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
    75
    ^ self readFrom: (ReadStream on: aString).
8fa257692c35 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
    76
8fa257692c35 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
    77
    "Modified (format): / 20-08-2011 / 16:46:39 / cg"
8fa257692c35 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
    78
!
8fa257692c35 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
    79
8749
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    80
hour:h minute:m
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    81
    "compatibility"
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    82
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    83
    ^ self hours:h minutes:m seconds:0
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    84
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    85
    "
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    86
     Time hour:2 minute:33 
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    87
    "
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    88
!
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
    89
7818
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    90
hour:h minute:m second:s
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    91
    "compatibility"
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    92
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    93
    ^ self hours:h minutes:m seconds:s
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    94
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    95
    "
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    96
     Time hour:2 minute:33 second:0 
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    97
    "
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    98
!
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
    99
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   100
hour:h minutes:m seconds:s
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   101
    "return an instance of Time representing the given time.
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   102
     See also Time now / Date today / Timestamp now.
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   103
     Obsolete: please use #hours:minutes:seconds:"
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
    <resource:#obsolete>
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   106
9061
20af48b9b295 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8994
diff changeset
   107
    self obsoleteMethodWarning:'use #hours:minutes:seconds:'.
6165
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
    ^ self hours:h minutes:m seconds:s
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   110
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   111
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   112
     Time hours:2 minutes:33 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   113
     Time hours:0 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   114
     Time hours:24 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   115
     Time hours23 minutes:59 seconds:59 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   116
    "
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
    "Modified: 19.4.1996 / 15:32:40 / cg"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   119
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   120
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   121
hours:h minutes:m seconds:s
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   122
    "return an instance of Time representing the given time.
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   123
     See also Time now / Date today / Timestamp now."
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   124
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   125
    ^ self basicNew setHours:h minutes:m seconds:s
4031
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
    "
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   128
     Time hours:2 minutes:33 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   129
     Time hours:0 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   130
     Time hours:24 minutes:0 seconds:0 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   131
     Time hours:23 minutes:59 seconds:59 
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   132
    "
6165
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
    "Modified: 19.4.1996 / 15:32:40 / cg"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   135
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   136
7293
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   137
midnight
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   138
    "Answer a new instance at midnight."
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   139
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   140
    ^ self fromSeconds: 0
7293
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   141
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   142
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   143
     Time midnight
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   144
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   145
!
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   146
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   147
noon
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   148
    "Answer a new instance at noon."
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   149
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   150
    ^ self fromSeconds: 43200 "12*60*60"
7293
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   151
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   152
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   153
     Time noon
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   154
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   155
!
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   156
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   157
readFrom:aStringOrStream onError:exceptionBlock
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   158
    "return a new Time, reading a printed representation from aStream.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   159
     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
   160
     either 24 hour format or being am."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   161
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   162
    ^ [
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   163
        |str hour min sec peekC|
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   164
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   165
        str := aStringOrStream readStream.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   166
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   167
        hour := Integer readFrom:str.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   168
        (hour between:0 and:24) ifFalse:[^ 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
        min := 0.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   171
        sec := 0.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   172
        str atEnd ifFalse:[
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   173
            peekC := str peek.
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   174
            (peekC == $:) ifTrue:[
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   175
                str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   176
                min := Integer readFrom:str.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   177
                (min between:0 and:59) ifFalse:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   178
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   179
                (str peek == $:) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   180
                    str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   181
                    sec := Integer readFrom:str.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   182
                    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   183
                ].
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   184
                peekC := str peek.
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   185
            ].
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   186
            [peekC == Character space] whileTrue:[str next. peekC := str peek].
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   187
            (peekC == $p or:[peekC == $P]) ifTrue:[
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   188
                str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   189
                (str peek == $m or:[str peek == $M]) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   190
                    str next
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   191
                ].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   192
                (hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value].
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   193
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   194
                "pm"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   195
                hour ~~ 12 ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   196
                    hour := hour + 12
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   197
                ].
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   198
                peekC := str peek
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   199
            ] ifFalse:[
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   200
                (peekC == $a or:[peekC == $A]) ifTrue:[
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   201
                    str next.
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   202
                    (str peek == $m or:[str peek == $M]) ifTrue:[
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   203
                        str next
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   204
                    ].
7240
341d1ac49d42 Handle 12:10 am correct when reading times.
Stefan Vogel <sv@exept.de>
parents: 7118
diff changeset
   205
                    hour == 12 ifTrue:[
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   206
                        hour := 0.
7240
341d1ac49d42 Handle 12:10 am correct when reading times.
Stefan Vogel <sv@exept.de>
parents: 7118
diff changeset
   207
                    ].
341d1ac49d42 Handle 12:10 am correct when reading times.
Stefan Vogel <sv@exept.de>
parents: 7118
diff changeset
   208
                    hour > 12 ifTrue:[^ exceptionBlock value].
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   209
                    peekC := str peek
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   210
                ] ifFalse:[
17728
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   211
                    "/ cg: dont be too picky here - we do not care, what comes after the
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   212
                    "/ time string. (Needed to be able to read rfc822 strings where a timezone
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   213
                    "/ follows (-/+0700 GMT, for example)
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   214
"/                    peekC notNil ifTrue:[
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   215
"/                        peekC isSeparator ifFalse:[^ exceptionBlock value].
bbc5fa73dfab Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17711
diff changeset
   216
"/                    ]
11308
fa79c438bb34 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11151
diff changeset
   217
                ].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   218
            ]
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   219
        ].
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   220
        self basicNew setHours:hour minutes:min seconds:sec
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   221
    ] on:Error do:exceptionBlock.
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   222
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   223
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   224
     Time readFrom:'0:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   225
     Time readFrom:'2:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   226
     Time readFrom:'12:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   227
     Time readFrom:'14:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   228
     Time readFrom:'23:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   229
     Time readFrom:'24:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   230
     Time readFrom:'2:30 am'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   231
     Time readFrom:'2:30 pm'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   232
     Time readFrom:'14'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   233
     Time readFrom:'2 am'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   234
     Time readFrom:'2 pm'    
7240
341d1ac49d42 Handle 12:10 am correct when reading times.
Stefan Vogel <sv@exept.de>
parents: 7118
diff changeset
   235
     Time readFrom:'12:05 pm'    
341d1ac49d42 Handle 12:10 am correct when reading times.
Stefan Vogel <sv@exept.de>
parents: 7118
diff changeset
   236
     Time readFrom:'12:06 am'    
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   237
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   238
     Time readFrom:'18:22:00'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   239
     Time readFrom:'14:00:11'    
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   240
     Time readFrom:'7:00:11'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   241
     Time readFrom:'24:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   242
     Time readFrom:'0:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   243
     Time readFrom:'12:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   244
     Time readFrom:'0:00:00'     
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   245
     Time readFrom:'6:22:00 pm'   
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   246
     Time readFrom:'2:00:11 pm'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   247
     Time readFrom:'7:00:11 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   248
     Time readFrom:'12:00:00 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   249
     Time readFrom:'0:00:00 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   250
     Time readFrom:'24:00:00 am'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   251
     Time readFrom:'12:00:00 pm'  
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   252
     Time readFrom:'0:00:00 pm' onError:'invalid'
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   253
     Time readFrom:'24:00:00 pm'  
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   254
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   255
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   256
    "Modified: 8.10.1996 / 19:32:11 / cg"
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   257
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   258
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   259
utcNow
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   260
    "return an instance of myself representing this moment."
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   261
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   262
    ^ self basicNew fromUtcOSTime:(OperatingSystem getOSTime)
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   263
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   264
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   265
     Timestamp now   
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   266
     Timestamp utcNow
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   267
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   268
     Time now   
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   269
     Time utcNow   
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   270
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   271
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   272
    "Modified: 1.7.1996 / 15:20:10 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   274
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   275
!Time class methodsFor:'format strings'!
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   276
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   277
defaultFormatString
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   278
    LanguageTerritory == #us ifTrue:[
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   279
        ^ self formatString12us
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   280
    ] ifFalse:[
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   281
        ^ self formatString24
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   282
    ]
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   283
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   284
    "Created: / 16-01-2011 / 11:23:36 / cg"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   285
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   286
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   287
formatString12us
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   288
    "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
   289
8231
0006aff04952 12 hour time (am/pm uppercase)
ca
parents: 8199
diff changeset
   290
    ^ '%u:%m:%s %A'
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   291
!
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   292
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   293
formatString24
8231
0006aff04952 12 hour time (am/pm uppercase)
ca
parents: 8199
diff changeset
   294
    "return the format string used to format non US times"
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   295
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   296
    ^ '%h:%m:%s'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   297
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   298
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17859
diff changeset
   299
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7240
diff changeset
   300
!Time methodsFor:'Compatibility-Squeak'!
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   301
17859
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   302
asMilliseconds
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   303
    ^ self asMilliSeconds
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   304
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   305
    "Created: / 05-09-2011 / 14:56:36 / cg"
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   306
!
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   307
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   308
intervalString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   309
    "Treat the time as a difference.  
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   310
     Give it in hours and minutes with two digits of accuracy."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   311
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   312
    |hours minutes seconds hh mm ss s|
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   313
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   314
    hours := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   315
    minutes := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   316
    seconds := self seconds.
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   317
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   318
    hours = 0   
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   319
        ifTrue: [hh := ''] 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   320
        ifFalse: [
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   321
            hh := hours printString, ' hour'.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   322
            hours > 1 ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   323
                hh := hh , 's'
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   324
            ]
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   325
        ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   326
    minutes = 0 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   327
        ifTrue: [mm := ''] 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   328
        ifFalse: [
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   329
            mm := minutes printString, ' minute'.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   330
            minutes > 1 ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   331
                mm := mm , 's'
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   332
            ]
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   333
        ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   334
    seconds = 0 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   335
        ifTrue: [ss := ''] 
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   336
        ifFalse: [
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   337
            ss := seconds printString, ' second'.
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   338
            seconds > 1 ifTrue:[
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   339
                ss := ss , 's'
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   340
            ]
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   341
        ].
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   342
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   343
    "/ do not show seconds, if hours are there
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   344
    hh size > 0 ifTrue: [ss := ''].
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   345
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   346
    s := hh.
6873
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   347
    mm notEmpty ifTrue:[
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   348
        s notEmpty ifTrue:[
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   349
            s := s , ' '
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   350
        ].
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   351
        s := s , mm.
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   352
    ].
6873
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   353
    ss notEmpty ifTrue:[
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   354
        s notEmpty ifTrue:[
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   355
            s := s , ' '
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   356
        ].
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   357
        s := s , ss
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   358
    ].
6873
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   359
    ^ s
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   360
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   361
    "
6873
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   362
     (Time fromSeconds:3600) intervalString     
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   363
     (Time fromSeconds:3605) intervalString    
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   364
     (Time fromSeconds:3700) intervalString    
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   365
     (Time fromSeconds:5) intervalString       
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   366
     (Time fromSeconds:65) intervalString      
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   367
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   368
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   369
7024
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   370
print24:prnt24FormatBoolean on:aStream
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   371
    "print me either US or 24hr format on a stream"
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   372
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   373
    ^ self print24:prnt24FormatBoolean showSeconds:true on:aStream
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   374
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   375
    "
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   376
     Time now print24:true on:Transcript. Transcript cr.
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   377
     Time now print24:false on:Transcript. Transcript cr.
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   378
    "
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   379
!
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   380
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   381
print24:prnt24Format showSeconds:doSeconds on:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   382
    "print me either US or 24hr format, optionally with
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   383
     seconds on a stream"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   384
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   385
    |format|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   386
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   387
    prnt24Format ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   388
        doSeconds ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   389
            format := '%h:%m:%s'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   390
        ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   391
            format := '%h:%m'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   392
        ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   393
    ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   394
        "/ US format
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   395
        doSeconds ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   396
            format := '%u:%m:%s %a'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   397
        ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   398
            format := '%u:%m %a'
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   399
        ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   400
    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   401
    ^ self
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   402
        printOn:aStream 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   403
        format:format.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   404
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   405
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   406
     Time now print24:true showSeconds:true on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   407
     Time now print24:false showSeconds:true on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   408
     Time now print24:true showSeconds:false on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   409
     Time now print24:false showSeconds:false on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   410
    "
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   411
! !
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   412
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   413
!Time methodsFor:'accessing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   414
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   415
hours
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   416
    "return the number of hours since midnight (i.e. 0..23)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   417
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   418
    ^ self getSeconds // 3600
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   419
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   420
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   421
     Time now hours
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   422
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   423
!
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   424
4845
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   425
milliseconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   426
    "time does not keep milliseconds 
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   427
     - for compatibility with Timestamp"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   428
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   429
    ^ 0
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   430
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   431
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   432
minutes
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   433
    "return the number of minutes within the hour (i.e. 0..59)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   434
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   435
    ^ (self getSeconds \\ 3600) // 60
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   436
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   437
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   438
     Time now minutes
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   439
    "
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
seconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   443
    "return the number of seconds within the minute (i.e. 0..59)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   444
7733
f556d689cf53 Speed up computations
Stefan Vogel <sv@exept.de>
parents: 7672
diff changeset
   445
    ^ self getSeconds \\ 60
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   446
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   447
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   448
     Time now seconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   449
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   450
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   451
9441
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   452
timeZoneDeltaInMinutes
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   453
    "answer the number of minutes between local time and utc time.
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   454
     Delta is positive if local time is ahead of utc, negative if behind utc.
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   455
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   456
     Time is local time, so answer the delta of today"
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   457
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   458
    ^ Timestamp now timeZoneDeltaInMinutes
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   459
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   460
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   461
    "
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   462
      Time now timeZoneDeltaInMinutes
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   463
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   464
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   465
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   466
!Time methodsFor:'comparing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   467
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   468
< aTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   469
    "return true if the receiver is before the argument"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   470
10744
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   471
    aTime class == self class ifTrue:[
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   472
        ^ timeEncoding < aTime timeEncoding
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   473
    ].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   474
    ^ self getSeconds < aTime getSeconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   475
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   476
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   477
= aTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   478
    "return true if the argument, aTime represents the same timeOfDay"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   479
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   480
    aTime class == self class ifTrue:[
10666
609bedc85066 changed #'=' (for largeinteger timeEncodings in TimeDuration)
Claus Gittinger <cg@exept.de>
parents: 9441
diff changeset
   481
        ^ timeEncoding = aTime timeEncoding
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   482
    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   483
    (aTime species == self species) ifFalse:[^ false].
10666
609bedc85066 changed #'=' (for largeinteger timeEncodings in TimeDuration)
Claus Gittinger <cg@exept.de>
parents: 9441
diff changeset
   484
    ^ self getSeconds = aTime getSeconds
609bedc85066 changed #'=' (for largeinteger timeEncodings in TimeDuration)
Claus Gittinger <cg@exept.de>
parents: 9441
diff changeset
   485
609bedc85066 changed #'=' (for largeinteger timeEncodings in TimeDuration)
Claus Gittinger <cg@exept.de>
parents: 9441
diff changeset
   486
    "Modified: / 18-07-2007 / 14:16:34 / cg"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   487
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   488
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   489
> aTime
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   490
    "return true if the receiver is before the argument"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   491
10744
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   492
    aTime class == self class ifTrue:[
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   493
        ^ timeEncoding > aTime timeEncoding
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   494
    ].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   495
    ^ self getSeconds > aTime getSeconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   496
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   497
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   498
hash
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   499
    "return an integer useful for hashing on times"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   500
10744
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   501
    ^ timeEncoding
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   502
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   503
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   504
!Time methodsFor:'converting'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   505
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   506
asLocalTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   507
    "return an Timestamp object from the receiver.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   508
     So I am interpreted as a Time in the local timezone.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   509
     The date components are taken from today."
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   510
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   511
    |todayTimestamp|
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   512
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   513
    todayTimestamp := Timestamp now.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   514
    todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   515
                   hour:(self hours) minute:(self minutes) second:(self seconds)
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   516
                   millisecond:(self milliseconds).
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   517
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   518
    ^ todayTimestamp.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   519
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   520
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   521
      Time now asLocalTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   522
    "
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   523
!
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   524
17859
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   525
asMilliSeconds
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   526
    "return the number of milliseconds elapsed since midnight"
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   527
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   528
    ^ self getMilliseconds
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   529
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   530
    "
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   531
     Time now asMilliSeconds
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   532
     (TimeDuration days:1) asMilliSeconds 
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   533
     (TimeDuration hours:1) asMilliSeconds 
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   534
    "
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   535
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   536
    "Created: / 05-09-2011 / 10:40:15 / cg"
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   537
!
cc167a69671c Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17850
diff changeset
   538
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   539
asSeconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   540
    "return the number of seconds elapsed since midnight"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   541
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   542
    ^ self getSeconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   543
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   544
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   545
     Time now asSeconds
10933
01e6c805b3df comment
Claus Gittinger <cg@exept.de>
parents: 10744
diff changeset
   546
     (TimeDuration days:1) asSeconds 
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   547
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   548
!
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   549
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   550
asTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   551
    "return a Time object from the receiver - thats the receiver."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   552
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   553
    ^ self
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   554
!
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   555
8796
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   556
asTimeDuration
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   557
    "return an TimeDuration object from the receiver, taking the time since midnight."
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   558
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   559
    ^ TimeDuration 
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   560
                   hours:(self hours) minutes:(self minutes) seconds:(self seconds)
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   561
                   milliseconds:(self milliseconds)
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   562
    "
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   563
     Time now asTimeDuration 
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   564
    "
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   565
!
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   566
8994
cbf9e75584fe asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents: 8796
diff changeset
   567
asTimestamp
cbf9e75584fe asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents: 8796
diff changeset
   568
    "return an Timestamp object from the receiver.
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   569
     The date components are taken from today."
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   570
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   571
    ^ self asLocalTimestamp
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   572
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   573
    "
8994
cbf9e75584fe asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents: 8796
diff changeset
   574
      Time now asTimestamp
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   575
    "
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   576
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   577
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   578
asUtcTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   579
    "return an UtcTimestamp object from the receiver.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   580
     So I am interpreted as a Time in the UTC zone.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   581
     The date components are taken from today."
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   582
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   583
    |todayTimestamp|
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   584
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   585
    todayTimestamp := UtcTimestamp now.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   586
    todayTimestamp year:todayTimestamp year month:todayTimestamp month day:todayTimestamp day
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   587
                   hour:(self hours) minute:(self minutes) second:(self seconds)
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   588
                   millisecond:(self milliseconds).
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   589
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   590
    ^ todayTimestamp.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   591
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   592
    "
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   593
      Time now asUtcTimestamp
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   594
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   595
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   596
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   597
!Time methodsFor:'printing & storing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   598
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   599
print12HourFormatOn:aStream
11151
61a33963c219 comments
Claus Gittinger <cg@exept.de>
parents: 10933
diff changeset
   600
    "append a human readable printed representation of the receiver to aStream.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   601
     Format is hh:mm:ss am/pm (i.e. 12-hour american format)."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   602
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   603
    ^ self
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   604
        printOn:aStream 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   605
        format:(self class formatString12us)
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   606
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   607
"/    |h m s ampm|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   608
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   609
"/    h := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   610
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   611
"/    "/ 0 -> 12 am
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   612
"/    "/ 12 -> 12 pm
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   613
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   614
"/    h // 12 == 0 ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   615
"/        ampm := ' am'.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   616
"/    ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   617
"/        ampm := ' pm'.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   618
"/    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   619
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   620
"/    h == 0 ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   621
"/        h := h - 1 \\ 12 + 1.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   622
"/    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   623
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   624
"/    h printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   625
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   626
"/    m := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   627
"/    (m < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   628
"/    m printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   629
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   630
"/    s := self seconds.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   631
"/    (s < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   632
"/    s printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   633
"/    aStream nextPutAll:ampm
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   634
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   635
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   636
     Time now print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   637
     (Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   638
     (Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   639
     (Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   640
     (Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   641
     0 to:24 do:[:h |
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   642
         (Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   643
     ]
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   644
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   645
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   646
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   647
print24HourFormatOn:aStream
11151
61a33963c219 comments
Claus Gittinger <cg@exept.de>
parents: 10933
diff changeset
   648
    "append a human readable printed representation of the receiver to aStream.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   649
     Format is hh:mm:ss (i.e. 24-hour european format)."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   650
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   651
    ^ self
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   652
        printOn:aStream 
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   653
        format:(self class formatString24).
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   654
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   655
"/    |h m s|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   656
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   657
"/    h := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   658
"/    (h < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   659
"/    h printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   660
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   661
"/    m := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   662
"/    (m < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   663
"/    m printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   664
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   665
"/    s := self seconds.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   666
"/    (s < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   667
"/    s printOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   668
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   669
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   670
     Time now print24HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   671
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   672
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   673
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   674
printOn:aStream
11151
61a33963c219 comments
Claus Gittinger <cg@exept.de>
parents: 10933
diff changeset
   675
    "append a human readable printed representation of the receiver to aStream.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   676
     The format is suitable for a human - not meant to be read back.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   677
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   678
     Format is hh:mm:ss either in 12-hour or 24-hour format.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   679
     depending on the setting of LanguageTerritory.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   680
     I dont know what ST-80 does here (12-hour format ?)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   681
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   682
    ^ self
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   683
        printOn:aStream 
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   684
        format:(self class defaultFormatString)               
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   685
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   686
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   687
     Time now printOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   688
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   689
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   690
    "Modified: / 16-01-2011 / 11:27:24 / cg"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   691
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   692
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   693
printString12HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   694
    "return a printed representation in 12 hour format"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   695
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   696
    ^ self printStringFormat:(self class formatString12us)               
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   697
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   698
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   699
     Time now printString12HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   700
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   701
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   702
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   703
printString24HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   704
    "return a printed representation in 24 hour format"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   705
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   706
    ^ self printStringFormat:(self class formatString24)               
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   707
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   708
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   709
     Time now printString24HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   710
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   711
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   712
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   713
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   714
shortPrintString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   715
    "dummy - for now"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   716
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   717
    ^ self printString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   718
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   719
    "Created: 20.6.1997 / 17:17:01 / cg"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   720
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   721
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   722
!Time methodsFor:'private'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   723
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   724
fromOSTime:osTime
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   725
    "set my time in the local timezone, given an osTime"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   726
7513
8a39ab36a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7293
diff changeset
   727
    |i|
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   728
7513
8a39ab36a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7293
diff changeset
   729
    i := OperatingSystem computeTimeAndDateFrom:osTime.
7740
5a9d544b8906 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7733
diff changeset
   730
    self setHours:(i hours) minutes:(i minutes) seconds:(i seconds)
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   731
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   732
    "Modified: 1.7.1996 / 15:21:06 / cg"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   733
!
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   734
17815
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   735
fromUtcOSTime:osTime
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   736
    "set my time in the local timezone, given an osTime"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   737
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   738
    |i|
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   739
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   740
    i := OperatingSystem computeUTCTimeAndDateFrom:osTime.
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   741
    self setHours:(i hours) minutes:(i minutes) seconds:(i seconds)
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   742
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   743
    "Modified: 1.7.1996 / 15:21:06 / cg"
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   744
!
956b46750806 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17814
diff changeset
   745
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   746
getMilliseconds
6046
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   747
    "return the number of milliseconds since midnight"
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   748
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   749
    ^ self getSeconds * 1000
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   750
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   751
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   752
getSeconds
6046
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   753
    "return the number of seconds since midnight"
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
   754
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   755
    ^ timeEncoding
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   756
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   757
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   758
setHours:h minutes:m seconds:s
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   759
    "set my time given individual values"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   760
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   761
    self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s).
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   762
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   763
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   764
setMilliseconds:millis
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   765
    "set my time given milliseconds since midnight"
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
   766
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   767
    self setSeconds:(millis // 1000)
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   768
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   769
6904
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   770
setSeconds:secs
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   771
    "set my time given seconds since midnight.
9441
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   772
     Notice the modulo operations here - there cannot be a time beyond 24hours
6904
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   773
     (use TimeDuration, if you need that)."
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   774
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   775
    secs < 0 ifTrue:[
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   776
        timeEncoding := (24 * 3600) - (secs negated \\ (24 * 3600))
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   777
    ] ifFalse:[
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   778
        timeEncoding := secs
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   779
    ].
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   780
    timeEncoding > (24 * 3600) ifTrue:[
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   781
        timeEncoding := timeEncoding \\ (24 * 3600).
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   782
    ]
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   783
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   784
    "
7011
4d7910fcaa7e add methods for squeak compatibility
penk
parents: 6904
diff changeset
   785
     Time basicNew setSeconds:0 
4d7910fcaa7e add methods for squeak compatibility
penk
parents: 6904
diff changeset
   786
     Time fromSeconds:3601  
6904
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   787
     Time now seconds
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   788
     Time now timeEncoding
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   789
     (Time now addDays:5) seconds     
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   790
     (Time now addDays:5) timeEncoding
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   791
    "
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   792
!
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
   793
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   794
timeEncoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   795
    "the internal encoding is stricktly private, 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   796
     and should not be used outside."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   797
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   798
    ^ timeEncoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   799
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   800
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   801
timeEncoding:encoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   802
    "the internal encoding is stricktly private, 
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   803
     and should not be used outside."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   804
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   805
    timeEncoding := encoding
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   806
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   807
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17859
diff changeset
   808
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   809
!Time class methodsFor:'documentation'!
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
   810
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   811
version
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
   812
    ^ '$Header: /cvs/stx/stx/libbasic/Time.st,v 1.92 2011/09/05 13:03:28 cg Exp $'
17751
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   813
!
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   814
b2273fa8d59f Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17728
diff changeset
   815
version_CVS
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17859
diff changeset
   816
    ^ '§Header: /cvs/stx/stx/libbasic/Time.st,v 1.92 2011/09/05 13:03:28 cg Exp §'
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17859
diff changeset
   817
!
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17859
diff changeset
   818
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17859
diff changeset
   819
version_SVN
17911
a99f15c5efa5 Updated with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17910
diff changeset
   820
    ^ '$Id: Time.st 10761 2012-01-19 11:46:00Z vranyj1 $'
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
   821
! !
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
   822
17910
8d796ca8bd1d Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17892
diff changeset
   823
17911
a99f15c5efa5 Updated with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17910
diff changeset
   824