Time.st
author Stefan Vogel <sv@exept.de>
Wed, 15 Apr 2020 20:18:14 +0200
changeset 25357 cec6ca6e3af4
parent 25221 4fcb818b33a1
permissions -rw-r--r--
#BUGFIX by stefan class: FileStream changed: #copy:into:bufferSize: Unix: check that UnixOperatingSystem class >> #copyFromFd:toFd:startIndex:count: copied all the data
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22809
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
     1
"{ Encoding: utf8 }"
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    14
"{ Package: 'stx:libbasic' }"
5390
5a7c0581cfce comment changes
Claus Gittinger <cg@exept.de>
parents: 4999
diff changeset
    15
17641
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    16
"{ NameSpace: Smalltalk }"
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    17
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    18
AbstractTime subclass:#Time
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    19
	instanceVariableNames:'timeEncoding'
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    20
	classVariableNames:''
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    21
	poolDictionaries:''
7672
46f206594db3 Category change
Stefan Vogel <sv@exept.de>
parents: 7513
diff changeset
    22
	category:'Magnitude-Time'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    25
!Time class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 COPYRIGHT (c) 1989 by Claus Gittinger
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    30
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
    Instances of time represent a particular time-of-day.
409
claus
parents: 394
diff changeset
    44
    Since they only store hours, minutes and seconds within a day,
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
    45
    they cannot be used to compare times across midnight
409
claus
parents: 394
diff changeset
    46
    (i.e. they should not be used as timeStamps).
1228
127d990e2f77 commentary
Claus Gittinger <cg@exept.de>
parents: 993
diff changeset
    47
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
    48
    Use instances of Timestamp (and read the comment there) to do this.
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    49
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
    50
    Time now returns the time in the local timezone.
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    51
    Use Time utcNow to get the time in the UTC zone; 
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    52
    bare in mind that, Time instances are not prepared and made for time zone aware
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    53
    time handling: always use Timestamp instances.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    54
    
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    55
    Note: 
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    56
      Time was changed recently to keep the number of milliseconds since midnight.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    57
      However, all existing instance creators so far only create time instances with 0-millis.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    58
      I.e. 'Time now' still returns a time with second precision.
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
    59
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    60
      It is not done currently, to remain backward compatible, as users may get confused
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    61
      to see t1 > t2 although they print the same 
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    62
      (as long as the printed representation does not include the milliseconds).
16937
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
    63
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    64
      On the other hand: 
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    65
            a change of the default printformat is not done, 
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    66
            as it may affect many existing applications.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    67
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    68
      Any application which needs the millisecond precision time should call the new
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
    69
        Time nowWithMilliseconds.
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
    70
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    71
    Examples:
17641
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    72
        |t|
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    73
17641
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    74
        t := Time now.
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    75
        Transcript showCR:t.
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    76
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    77
17641
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    78
        |t1 t2|
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
    79
17641
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    80
        t1 := Time now.
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    81
        (Delay forSeconds:10) wait.
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    82
        t2 := Time now.
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    83
        t2 - t1
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    84
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    85
    [author:]
17641
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    86
        Claus Gittinger
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    87
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1228
diff changeset
    88
    [see also:]
17641
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    89
        Date Timestamp AbstractTime OperatingSystem
e28a4212f412 class: Time
Claus Gittinger <cg@exept.de>
parents: 17162
diff changeset
    90
        Filename
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    91
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    92
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    94
!Time class methodsFor:'instance creation'!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
    95
13603
d9baa85cd3ba comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents: 13235
diff changeset
    96
fromString: aString
d9baa85cd3ba comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents: 13235
diff changeset
    97
    ^ self readFrom: (ReadStream on: aString).
d9baa85cd3ba comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents: 13235
diff changeset
    98
d9baa85cd3ba comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents: 13235
diff changeset
    99
    "Modified (format): / 20-08-2011 / 16:46:39 / cg"
d9baa85cd3ba comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents: 13235
diff changeset
   100
!
d9baa85cd3ba comment/format in: #fromString:
Claus Gittinger <cg@exept.de>
parents: 13235
diff changeset
   101
8749
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   102
hour:h minute:m
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   103
    "compatibility"
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   104
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   105
    <resource:#obsolete>
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   106
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   107
    self obsoleteMethodWarning:'use #hours:minutes:seconds:'.
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   108
8749
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   109
    ^ self hours:h minutes:m seconds:0
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   110
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   111
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   112
     Time hour:2 minute:33
8749
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   113
    "
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   114
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   115
    "Modified: / 17-07-2017 / 14:04:39 / cg"
8749
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   116
!
2efa8ed1f9f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8249
diff changeset
   117
7818
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   118
hour:h minute:m second:s
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   119
    "compatibility"
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   120
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   121
    <resource:#obsolete>
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   122
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   123
    self obsoleteMethodWarning:'use #hours:minutes:seconds:'.
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   124
7818
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   125
    ^ self hours:h minutes:m seconds:s
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   126
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   127
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   128
     Time hour:2 minute:33 second:0
7818
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   129
    "
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   130
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   131
    "Modified: / 17-07-2017 / 14:04:34 / cg"
7818
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   132
!
30eb2226645b +hour:minute:second:
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
   133
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   134
hour:h minutes:m seconds:s
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   135
    "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
   136
     See also Time now / Date today / Timestamp now.
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   137
     Obsolete: please use #hours:minutes:seconds:"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   138
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   139
    <resource:#obsolete>
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   140
9061
20af48b9b295 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8994
diff changeset
   141
    self obsoleteMethodWarning:'use #hours:minutes:seconds:'.
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   142
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   143
    ^ self hours:h minutes:m seconds:s
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   144
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   145
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   146
     Time hours:2 minutes:33 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   147
     Time hours:0 minutes:0 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   148
     Time hours:24 minutes:0 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   149
     Time hours23 minutes:59 seconds:59
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   150
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   151
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   152
    "Modified: 19.4.1996 / 15:32:40 / cg"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   153
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   154
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   155
hours:h minutes:m
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   156
    "return a new TimeDuration representing a duration of h hours and m minutes.
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   157
     See also Time now / Date today / Timestamp now."
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   158
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   159
    ^ self basicNew setHours:h minutes:m seconds:0 milliseconds:0
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   160
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   161
    "
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   162
     TimeDuration hours:2 minutes:33 
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   163
     TimeDuration hours:100 minutes:33  
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   164
    "
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   165
!
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   166
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   167
hours:h minutes:m seconds:s
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   168
    "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
   169
     See also Time now / Date today / Timestamp now."
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   170
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   171
    ^ self basicNew setHours:h minutes:m seconds:s
4031
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   172
de8ae1bf2827 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3995
diff changeset
   173
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   174
     Time hours:2 minutes:33 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   175
     Time hours:0 minutes:0 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   176
     Time hours:24 minutes:0 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   177
     Time hours:23 minutes:59 seconds:59
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   178
    "
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   179
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   180
    "Modified: 19.4.1996 / 15:32:40 / cg"
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   181
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   182
16937
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   183
hours:h minutes:m seconds:s milliseconds:ms
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   184
    "return an instance of Time representing the given time.
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   185
     See also Time now / Date today / Timestamp now."
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   186
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   187
    ^ self basicNew setHours:h minutes:m seconds:s milliseconds:ms
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   188
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   189
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   190
     Time hours:2 minutes:33 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   191
     Time hours:0 minutes:0 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   192
     Time hours:24 minutes:0 seconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   193
     Time hours:23 minutes:59 seconds:59
16937
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   194
    "
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   195
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   196
    "Modified: 19.4.1996 / 15:32:40 / cg"
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   197
!
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
   198
7293
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   199
midnight
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   200
    "Answer a new instance at midnight."
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   201
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   202
    ^ self fromSeconds: 0
7293
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   203
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   204
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   205
     Time midnight
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   206
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   207
!
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   208
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   209
noon
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   210
    "Answer a new instance at noon."
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   211
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   212
    ^ self fromSeconds: 43200 "12*60*60"
7293
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   213
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   214
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   215
     Time noon
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   216
    "
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   217
!
f042dd09afd3 +midnight
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
   218
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   219
readFrom:aStringOrStream format:formatString language:languageOrNil onError:exceptionalValue
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   220
    "return a new Time, reading a printed representation from aStream using a formatString.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   221
     The formatString is similar to the one used when printing.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   222
     On error, exceptionalValue is returned.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   223
     If exceptionalValue is a one-arg block, an error message is passed as argument.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   224
     Format:
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   225
        %h      hours, 00..23 (i.e. european)  0-padded to length 2
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   226
        %u      hours, 00..12 (i.e. us)        0-padded to length 2
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   227
        %m      minutes, 00..59                0-padded to length 2
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   228
        %s      seconds, 00..59                0-padded to length 2
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   229
        %i      milliseconds, 000..999         0-padded to length 3
19922
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   230
        %f      fractional seconds             any length, but only milliseconds are read
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   231
        %a      am/pm
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   232
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   233
     an optional length after the % gives a field length;
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   234
        i.e. %2h%2m%2s parses '123557' as 12:35:37
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   235
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   236
     Please consider using a standard format, such as iso8601.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   237
    "
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   238
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   239
    |hour minute second millisecond
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   240
     utcOffset inStream formatStream error fChar format itemHandler
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   241
     len s fraction fractionString peekc|
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   242
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   243
    error := [:msg |
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   244
                exceptionalValue isBlock ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   245
                    ^ exceptionalValue valueWithOptionalArgument:'format error'
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   246
                ] ifFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   247
                    ^ exceptionalValue value
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   248
                ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   249
             ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   250
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   251
    itemHandler := [:format |
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   252
        |input|
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   253
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   254
        input := len isNil ifTrue:[ inStream ] ifFalse:[ inStream next: len ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   255
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   256
        ( format = 'h' or:[ format = 'H' ]) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   257
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   258
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   259
        ] ifFalse:[ ( format = 'u'  or:[ format = 'U']) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   260
            hour := Integer readFrom:input onError:[ error value:'invalid hour' ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   261
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   262
        ] ifFalse:[ ( format = 'm'  or:[ format = 'M' ]) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   263
            minute := Integer readFrom:input onError:[ error value:'invalid minute' ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   264
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   265
        ] ifFalse:[ ( format = 's'  or:[ format = 'S' ]) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   266
            second := Integer readFrom:input onError:[ error value:'invalid second' ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   267
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   268
        ] ifFalse:[ ( format = 'i'  or:[ format = 'I' ]) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   269
            millisecond := Integer readFrom:input onError:[ error value:'invalid millsecond' ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   270
19922
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   271
        ] ifFalse:[ ( format = 'f'  or:[ format = 'F' ]) ifTrue:[
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   272
            fractionString := input upToMatching:[:ch | ch isDigit not].
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   273
            fraction := FixedPoint readFrom:'0.',fractionString.
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   274
            millisecond := (fraction * 1000) truncated.
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   275
        ] ifFalse:[ ( format = 'tz' ) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   276
            utcOffset := Timestamp utcOffsetFrom:input.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   277
            utcOffset isNil ifTrue:[ error value:'invalid timezone' ]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   278
        ] ifFalse:[ ( format = 'a' ) ifTrue:[
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   279
            input atEnd ifTrue:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   280
                "/ am pm missing; assume 24 hr format
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   281
                (hour between:0 and:24) ifFalse:[ error value:'invalid hour' ].
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   282
                (hour = 24) ifTrue:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   283
                    (minute > 0 or:[ second > 0 or:[ millisecond > 0 ]]) ifTrue:[ error value:'invalid hour' ].
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   284
                    hour := 0.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   285
                ]
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   286
            ] ifFalse:[
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   287
                s := (input next:2) asLowercase.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   288
                s = 'am' ifTrue:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   289
                    (hour between:0 and:12) ifFalse:[ error value:'invalid hour' ]
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   290
                ] ifFalse:[
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   291
                    s = 'pm' ifTrue:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   292
                        (hour between:1 and:12) ifFalse:[ error value:'invalid hour' ].
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   293
                        hour := hour + 12.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   294
                    ] ifFalse:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   295
                        error value:'invalid am/pm'
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   296
                    ]
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   297
                ]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   298
            ]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   299
        ] ifFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   300
            error value:'unhandled format:',format
19922
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   301
        ]]]]]]]]
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   302
    ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   303
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   304
    hour := 0.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   305
    minute := 0.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   306
    second := 0.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   307
    millisecond := 0.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   308
    utcOffset := 0.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   309
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   310
    inStream := aStringOrStream readStream.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   311
    formatStream := formatString readStream.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   312
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   313
    [formatStream atEnd] whileFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   314
        fChar := formatStream next.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   315
        fChar = Character space ifTrue:[
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   316
            (peekc := inStream peek) notNil ifTrue:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   317
                peekc isSeparator ifFalse:[ error value: 'space expcected' ].
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   318
                inStream skipSeparators.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   319
            ]
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   320
        ] ifFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   321
            fChar == $% ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   322
                len := nil.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   323
                (formatStream peek isDigit) ifTrue:[
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   324
                    len := Integer readFrom:formatStream onError:[ error value: 'invalid length in time format' ]
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   325
                ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   326
                (formatStream peek == $() ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   327
                    formatStream next.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   328
                    format := formatStream upTo:$).
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   329
                ] ifFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   330
                    (formatStream peek == ${) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   331
                        formatStream next.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   332
                        format := formatStream upTo:$}.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   333
                    ] ifFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   334
                        (formatStream peek isLetter) ifTrue:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   335
                            format := formatStream nextAlphaNumericWord.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   336
                        ] ifFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   337
                            error value:'unhandled format:',formatStream peek
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   338
                        ]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   339
                    ]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   340
                ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   341
                itemHandler value:format.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   342
            ] ifFalse:[
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   343
                inStream peek = fChar ifFalse:[^ error value: 'format error; ',fChar,' expcected'].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   344
                inStream next.
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   345
            ]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   346
        ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   347
    ].
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   348
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   349
    ^ (self 
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   350
        hours:(hour ? 0) minutes:(minute ? 0) seconds:(second ? 0) milliseconds:millisecond) 
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   351
            + utcOffset
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   352
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   353
    "
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   354
     Time readFrom:'13:11:06' format:'%h:%m:%s' language:nil onError:[self halt]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   355
     Time readFrom:'131106' format:'%2h%2m%2s' language:nil onError:[self halt]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   356
     Time readFrom:'7:30pm EST' format:'%u:%m%a %tz' language:#en onError:[self halt]
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   357
     Time readFrom:'7:30pm UTC' format:'%u:%m%a %tz' language:#en onError:[self halt]
19922
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   358
     
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   359
     Time readFrom:'13:11:06.111' format:'%h:%m:%s.%i' language:nil onError:[self halt]
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   360
     Time readFrom:'13:11:06.1' format:'%h:%m:%s.%f' language:nil onError:[self halt]
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   361
     Time readFrom:'13:11:06.01' format:'%h:%m:%s.%f' language:nil onError:[self halt]
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   362
     Time readFrom:'13:11:06.001' format:'%h:%m:%s.%f' language:nil onError:[self halt]
e0d6d301a4dc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19848
diff changeset
   363
     Time readFrom:'13:11:06.1234567' format:'%h:%m:%s.%f' language:nil onError:[self halt]
18456
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   364
    "
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   365
!
74744af7f90d class: Time
Claus Gittinger <cg@exept.de>
parents: 17641
diff changeset
   366
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   367
readFrom:aStringOrStream onError:exceptionBlock
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   368
    "return a new Time, reading a printed representation from aStream.
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   369
     If no am/pm follows the time, the string is interpreted as
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   370
     either 24 hour format or being am.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   371
     If it starts with T, assume iso8601 format"
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   372
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   373
    ^ [
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   374
        |str hour min sec peekC millis pos tB ts|
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   375
20818
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   376
        str := aStringOrStream readStream.
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   377
        (str peek == $T) ifTrue:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   378
            str next.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   379
            pos := str position.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   380
            Error handle:[:ex |
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   381
                self halt.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   382
            ] do:[
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   383
                tB := Timestamp::TimestampISO8601Builder new dateAlreadyReadAs:(Date today).
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   384
                tB stream:str; readTime; readTimezone.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   385
                ts := tB timestampWithClass:Timestamp.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   386
                ^ ts asTime
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   387
            ].
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   388
            str position:pos.
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   389
            ^ exceptionBlock value
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   390
        ].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   391
20818
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   392
        hour := Integer readFrom:str.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   393
        (hour between:0 and:24) ifFalse:[^ exceptionBlock value].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   394
20818
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   395
        min := 0.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   396
        sec := 0.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   397
        millis := 0.
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   398
20818
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   399
        str atEnd ifFalse:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   400
            peekC := str peek.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   401
            (peekC == $:) ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   402
                str next.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   403
                min := Integer readFrom:str.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   404
                (min between:0 and:59) ifFalse:[^ exceptionBlock value].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   405
20818
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   406
                (str peek == $:) ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   407
                    str next.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   408
                    sec := Integer readFrom:str.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   409
                    (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   410
                    (str peek == $.) ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   411
                        str next.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   412
                        millis := ((Fraction readDecimalFractionFrom:str onError:[^ exceptionBlock value]) * 1000) asInteger.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   413
                    ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   414
                ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   415
                peekC := str peek.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   416
            ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   417
            [peekC == Character space] whileTrue:[str next. peekC := str peek].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   418
            (peekC == $p or:[peekC == $P]) ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   419
                str next.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   420
                (str peek == $m or:[str peek == $M]) ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   421
                    str next
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   422
                ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   423
                (hour <= 0 or:[hour > 12]) ifTrue:[^ exceptionBlock value].
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   424
20818
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   425
                "pm"
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   426
                hour ~~ 12 ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   427
                    hour := hour + 12
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   428
                ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   429
                peekC := str peek
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   430
            ] ifFalse:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   431
                (peekC == $a or:[peekC == $A]) ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   432
                    str next.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   433
                    (str peek == $m or:[str peek == $M]) ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   434
                        str next
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   435
                    ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   436
                    hour == 12 ifTrue:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   437
                        hour := 0.
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   438
                    ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   439
                    hour > 12 ifTrue:[^ exceptionBlock value].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   440
                    peekC := str peek
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   441
                ] ifFalse:[
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   442
                    "/ cg: don't be too picky here - we do not care, what comes after the
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   443
                    "/ time string. (Needed to be able to read rfc822 strings where a timezone
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   444
                    "/ follows (-/+0700 GMT, for example)
11809
efca8cccc66b time reading: do not insist on peek-char to be a separator after the
Claus Gittinger <cg@exept.de>
parents: 11308
diff changeset
   445
"/                    peekC notNil ifTrue:[
efca8cccc66b time reading: do not insist on peek-char to be a separator after the
Claus Gittinger <cg@exept.de>
parents: 11308
diff changeset
   446
"/                        peekC isSeparator ifFalse:[^ exceptionBlock value].
efca8cccc66b time reading: do not insist on peek-char to be a separator after the
Claus Gittinger <cg@exept.de>
parents: 11308
diff changeset
   447
"/                    ]
20818
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   448
                ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   449
            ]
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   450
        ].
efa2de8569f6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20614
diff changeset
   451
        self basicNew setHours:hour minutes:min seconds:sec milliseconds:millis
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   452
    ] on:Error do:exceptionBlock.
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   453
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   454
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   455
     Time readFrom:'0:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   456
     Time readFrom:'2:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   457
     Time readFrom:'12:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   458
     Time readFrom:'14:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   459
     Time readFrom:'23:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   460
     Time readFrom:'24:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   461
     Time readFrom:'2:30 am'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   462
     Time readFrom:'2:30 pm'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   463
     Time readFrom:'14'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   464
     Time readFrom:'2 am'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   465
     Time readFrom:'2 pm'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   466
     Time readFrom:'12:05 pm'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   467
     Time readFrom:'12:06 am'
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   468
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   469
     Time readFrom:'18:22:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   470
     Time readFrom:'14:00:11'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   471
     Time readFrom:'7:00:11'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   472
     Time readFrom:'24:00:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   473
     Time readFrom:'0:00:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   474
     Time readFrom:'12:00:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   475
     Time readFrom:'0:00:00'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   476
     Time readFrom:'6:22:00 pm'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   477
     Time readFrom:'2:00:11 pm'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   478
     Time readFrom:'7:00:11 am'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   479
     Time readFrom:'12:00:00 am'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   480
     Time readFrom:'0:00:00 am'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   481
     Time readFrom:'24:00:00 am'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   482
     Time readFrom:'12:00:00 pm'
6624
886265eff14c #readFrom:onError: - avoid block creation
Stefan Vogel <sv@exept.de>
parents: 6467
diff changeset
   483
     Time readFrom:'0:00:00 pm' onError:'invalid'
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   484
     Time readFrom:'24:00:00 pm'
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   485
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   486
     Time readFrom:'13:00:00.5'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   487
     Time readFrom:'13:00:00.123'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   488
     Time readFrom:'1:00:00.123 pm'
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   489
    "
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   490
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   491
    "Modified: 8.10.1996 / 19:32:11 / cg"
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   492
!
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   493
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   494
utcNow
17136
0ef1bb251905 class: Time
Claus Gittinger <cg@exept.de>
parents: 17066
diff changeset
   495
    "return an instance of myself representing this moment in UTC.
0ef1bb251905 class: Time
Claus Gittinger <cg@exept.de>
parents: 17066
diff changeset
   496
     That is, the current time in London without any daylight saving adjustments."
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   497
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   498
    ^ self basicNew fromUtcOSTime:(OperatingSystem getOSTime)
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   499
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   500
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   501
     Timestamp now
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   502
     Timestamp utcNow
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   503
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   504
     Time now
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   505
     Time utcNow
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   506
    "
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   507
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   508
    "Modified: 1.7.1996 / 15:20:10 / cg"
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   509
!
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   510
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   511
utcNowWithMilliseconds
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   512
    "return an instance of myself representing this moment with at least millisecond precision."
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   513
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   514
    ^ self basicNew fromUtcOSTimeWithMilliseconds:(OperatingSystem getOSTime)
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   515
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   516
    "
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   517
     Time now                       -> 01:05:10 PM
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   518
     Time nowWithMilliseconds       -> 01:05:14.359 PM
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   519
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   520
     Time utcNow                    -> 11:05:16 AM
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   521
     Time utcNowWithMilliseconds    -> 11:05:18.753 AM
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   522
    "
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   523
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   524
    "Modified: 1.7.1996 / 15:20:10 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   525
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   526
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
   527
!Time class methodsFor:'format strings'!
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   528
13213
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
   529
defaultFormatString
16985
8d63397a4b9a class: Time
Claus Gittinger <cg@exept.de>
parents: 16981
diff changeset
   530
    "a language specific format string to present times in user interfaces.
8d63397a4b9a class: Time
Claus Gittinger <cg@exept.de>
parents: 16981
diff changeset
   531
     Do not use this to store/retrieve times (use ISO8601 for that)"
8d63397a4b9a class: Time
Claus Gittinger <cg@exept.de>
parents: 16981
diff changeset
   532
20614
0a5744a1f46c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19922
diff changeset
   533
    Smalltalk languageTerritory == #us ifTrue:[
0a5744a1f46c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19922
diff changeset
   534
        ^ self formatString12us
13213
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
   535
    ] ifFalse:[
20614
0a5744a1f46c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19922
diff changeset
   536
        ^ self formatString24
13213
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
   537
    ]
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
   538
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
   539
    "Created: / 16-01-2011 / 11:23:36 / cg"
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
   540
!
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
   541
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   542
defaultFormatStringWithMilliseconds
20614
0a5744a1f46c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19922
diff changeset
   543
    Smalltalk languageTerritory == #us ifTrue:[
0a5744a1f46c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19922
diff changeset
   544
        ^ self formatStringWithMilliseconds12us
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   545
    ] ifFalse:[
20614
0a5744a1f46c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19922
diff changeset
   546
        ^ self formatStringWithMilliseconds24
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   547
    ]
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   548
!
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   549
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   550
formatString12us
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   551
    "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
   552
8231
0006aff04952 12 hour time (am/pm uppercase)
ca
parents: 8199
diff changeset
   553
    ^ '%u:%m:%s %A'
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   554
!
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   555
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   556
formatString24
8231
0006aff04952 12 hour time (am/pm uppercase)
ca
parents: 8199
diff changeset
   557
    "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
   558
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   559
    ^ '%h:%m:%s'
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   560
!
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   561
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   562
formatStringWithMilliseconds12us
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   563
    "return the format string used to format US times (and other areas)"
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   564
16949
25f4ab2115b8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16940
diff changeset
   565
    ^ '%u:%m:%s.%i %A'
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   566
!
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   567
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   568
formatStringWithMilliseconds24
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   569
    "return the format string used to format non US times"
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   570
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   571
    ^ '%h:%m:%s.%i'
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   572
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   573
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   574
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
   575
16981
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   576
!Time methodsFor:'Compatibility-Backward'!
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   577
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   578
asMilliSeconds
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   579
    <resource: #obsolete>
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   580
    "return the number of milliseconds elapsed since midnight"
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   581
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   582
    ^ self asMilliseconds
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   583
16981
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   584
    "
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   585
     Time now asMilliSeconds
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   586
     (TimeDuration days:1) asMilliSeconds
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   587
     (TimeDuration hours:1) asMilliSeconds
16981
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   588
    "
13632
09ee3dad124c added: #asMilliseconds
Claus Gittinger <cg@exept.de>
parents: 13630
diff changeset
   589
16981
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   590
    "Created: / 05-09-2011 / 10:40:15 / cg"
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   591
! !
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   592
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   593
!Time methodsFor:'Compatibility-Squeak'!
13632
09ee3dad124c added: #asMilliseconds
Claus Gittinger <cg@exept.de>
parents: 13630
diff changeset
   594
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   595
intervalString
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   596
    "Treat the time as a difference.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   597
     Give it in hours and minutes with two digits of accuracy."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   598
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   599
    |hours minutes seconds hh mm ss s|
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   600
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   601
    hours := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   602
    minutes := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   603
    seconds := self seconds.
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   604
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   605
    hours = 0
23790
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   606
        ifTrue: [hh := '']
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   607
        ifFalse: [
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   608
            hh := hours printString, ' hour'.
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   609
            hours > 1 ifTrue:[
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   610
                hh := hh , 's'
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   611
            ]
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   612
        ].
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   613
    minutes = 0
23790
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   614
        ifTrue: [mm := '']
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   615
        ifFalse: [
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   616
            mm := minutes printString, ' minute'.
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   617
            minutes > 1 ifTrue:[
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   618
                mm := mm , 's'
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   619
            ]
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   620
        ].
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   621
    seconds = 0
23790
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   622
        ifTrue: [ss := '']
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   623
        ifFalse: [
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   624
            ss := seconds printString, ' second'.
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   625
            seconds > 1 ifTrue:[
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   626
                ss := ss , 's'
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   627
            ]
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   628
        ].
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   629
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   630
    "/ do not show seconds, if hours are there
23790
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   631
    hh size ~~ 0 ifTrue: [ss := ''].
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   632
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   633
    s := hh.
6873
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   634
    mm notEmpty ifTrue:[
23790
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   635
        s notEmpty ifTrue:[
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   636
            s := s , ' '
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   637
        ].
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   638
        s := s , mm.
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   639
    ].
6873
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   640
    ss notEmpty ifTrue:[
23790
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   641
        s notEmpty ifTrue:[
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   642
            s := s , ' '
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   643
        ].
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   644
        s := s , ss
6467
f200ac48f2a8 intervalString
Claus Gittinger <cg@exept.de>
parents: 6165
diff changeset
   645
    ].
6873
c70b04265d33 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6624
diff changeset
   646
    ^ s
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   647
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   648
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   649
     (Time fromSeconds:3600) intervalString
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   650
     (Time fromSeconds:3605) intervalString
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   651
     (Time fromSeconds:3700) intervalString
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   652
     (Time fromSeconds:5) intervalString
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   653
     (Time fromSeconds:65) intervalString
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   654
    "
23790
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   655
42e8ecc961bc #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23618
diff changeset
   656
    "Modified: / 01-03-2019 / 16:14:41 / Claus Gittinger"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   657
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   658
7024
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   659
print24:prnt24FormatBoolean on:aStream
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   660
    "print me either US or 24hr format on a stream"
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   661
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   662
    ^ self print24:prnt24FormatBoolean showSeconds:true on:aStream
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   663
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   664
    "
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   665
     Time now print24:true on:Transcript. Transcript cr.
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   666
     Time now print24:false on:Transcript. Transcript cr.
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   667
    "
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   668
!
aab4f98eb6b2 squeak: print24:on:
penk
parents: 7011
diff changeset
   669
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   670
print24:prnt24Format showSeconds:doSeconds on:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   671
    "print me either US or 24hr format, optionally with
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   672
     seconds on a stream"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   673
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   674
    |format|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   675
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   676
    prnt24Format ifTrue:[
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   677
	doSeconds ifTrue:[
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   678
	    format := '%h:%m:%s'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   679
	] ifFalse:[
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   680
	    format := '%h:%m'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   681
	].
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   682
    ] ifFalse:[
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   683
	"/ US format
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   684
	doSeconds ifTrue:[
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   685
	    format := '%u:%m:%s %a'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   686
	] ifFalse:[
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   687
	    format := '%u:%m %a'
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   688
	].
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   689
    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   690
    ^ self
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   691
	printOn:aStream
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   692
	format:format.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   693
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   694
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   695
     Time now print24:true showSeconds:true on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   696
     Time now print24:false showSeconds:true on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   697
     Time now print24:true showSeconds:false on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   698
     Time now print24:false showSeconds:false on:Transcript. Transcript cr.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   699
    "
4411
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   700
! !
684a2b944463 much improved formatting (see #printOn:format:)
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   701
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   702
!Time methodsFor:'accessing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   703
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   704
hours
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   705
    "return the number of hours since midnight (i.e. 0..23)"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   706
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   707
    ^ self getSeconds // 3600
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   708
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   709
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   710
     Time now hours
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   711
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   712
!
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
   713
4845
ffd67920b3a3 added dummy milliseconds.
Claus Gittinger <cg@exept.de>
parents: 4649
diff changeset
   714
milliseconds
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   715
    "get the milliseconds part
16981
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   716
     (notice: that is NOT the total number of millis (since midnight),
19848
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   717
     but the fractional part only. Use this only for printing.
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   718
     asMilliseconds or getMilliseconds is probably what you want"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   719
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
   720
    ^ timeEncoding \\ 1000
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   721
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   722
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   723
minutes
19848
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   724
    "return the number of minutes within the hour (i.e. 0..59).
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   725
     (notice: that is NOT the total number of minutes (since midnight),
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   726
     but the fractional part only. Use this only for printing."
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   727
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   728
    ^ (self getSeconds \\ 3600) // 60
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   729
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   730
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   731
     Time now minutes
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   732
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   733
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   734
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   735
seconds
19848
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   736
    "return the number of seconds within the minute (i.e. 0..59).
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   737
     (notice: that is NOT the total number of seconds (since midnight),
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   738
     but the fractional part only. Use this only for printing.
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
   739
     asSeconds or getSeconds give you the nr of seconds since midnight"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   740
7733
f556d689cf53 Speed up computations
Stefan Vogel <sv@exept.de>
parents: 7672
diff changeset
   741
    ^ self getSeconds \\ 60
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   742
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   743
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   744
     Time now seconds
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   745
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   746
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   747
9441
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   748
timeZoneDeltaInMinutes
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   749
    "answer the number of minutes between local time and utc time.
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   750
     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
   751
16985
8d63397a4b9a class: Time
Claus Gittinger <cg@exept.de>
parents: 16981
diff changeset
   752
     Time is local time, so ask a local timestamp"
9441
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   753
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   754
    ^ Timestamp now timeZoneDeltaInMinutes
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   755
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   756
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   757
    "
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   758
      Time now timeZoneDeltaInMinutes
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
   759
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   760
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   761
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   762
!Time methodsFor:'comparing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   763
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   764
hash
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   765
    "return an integer useful for hashing on times"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   766
10744
afd1835c12d2 comparison did only care for seconds, when used with timeDurations
sr
parents: 10666
diff changeset
   767
    ^ timeEncoding
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   768
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   769
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   770
!Time methodsFor:'converting'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   771
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   772
asLocalTimestamp
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   773
    "return an Timestamp object from the receiver.
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   774
     So I am interpreted as a Time in the local timezone.
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   775
     The date components are taken from today."
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   776
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   777
    |todayTimestamp|
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   778
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   779
    todayTimestamp := Timestamp now.
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   780
    todayTimestamp 
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   781
        year:todayTimestamp year 
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   782
        month:todayTimestamp month 
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   783
        day:todayTimestamp day
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   784
        hour:(self hours) 
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   785
        minute:(self minutes) 
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   786
        second:(self seconds)
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   787
        millisecond:(self milliseconds).
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   788
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   789
    ^ todayTimestamp.
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   790
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   791
    "
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   792
      Time now asLocalTimestamp
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   793
    "
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   794
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   795
    "Modified (format): / 17-07-2017 / 14:07:27 / cg"
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   796
!
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   797
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   798
asTZTimestamp
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   799
    "return a TZTimestamp object from the receiver.
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   800
     This includes the local timezone information."
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   801
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   802
    ^ self asLocalTimestamp asTZTimestamp.
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   803
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   804
    "
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   805
     Time now asTZTimestamp     -> 2017-07-17 14:11:16+02
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   806
     Time now asUtcTimestamp    -> 2017-07-17 12:11:16Z
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   807
     Time now asLocalTimestamp  -> 2017-07-17 14:11:16
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   808
    "
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   809
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   810
    "Created: / 17-07-2017 / 14:11:14 / cg"
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   811
!
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   812
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   813
asTime
16981
786f8b3f95bb class: Time
Claus Gittinger <cg@exept.de>
parents: 16949
diff changeset
   814
    "return a Time object from the receiver - that's the receiver."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   815
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   816
    self class == Time ifTrue:[
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   817
        ^ self
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   818
    ].
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   819
    ^ super asTime
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   820
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   821
    "Modified: / 17-07-2017 / 14:06:53 / cg"
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   822
!
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   823
8796
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   824
asTimeDuration
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   825
    "return an TimeDuration object from the receiver, taking the time since midnight."
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   826
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   827
    ^ TimeDuration
23618
72c9d0ab725d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23237
diff changeset
   828
                   hours:(self hours) minutes:(self minutes) seconds:(self seconds)
72c9d0ab725d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23237
diff changeset
   829
                   milliseconds:(self milliseconds)
8796
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   830
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   831
     Time now asTimeDuration
23618
72c9d0ab725d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23237
diff changeset
   832
     10 asTimeDuration
72c9d0ab725d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23237
diff changeset
   833
     10 seconds asTimeDuration
72c9d0ab725d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23237
diff changeset
   834
     '10m 20s' asTimeDuration
8796
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   835
    "
23618
72c9d0ab725d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23237
diff changeset
   836
72c9d0ab725d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23237
diff changeset
   837
    "Modified (comment): / 21-01-2019 / 10:29:05 / Claus Gittinger"
8796
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   838
!
1b9711a23424 +asTimeDuration
Claus Gittinger <cg@exept.de>
parents: 8749
diff changeset
   839
8994
cbf9e75584fe asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents: 8796
diff changeset
   840
asTimestamp
cbf9e75584fe asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents: 8796
diff changeset
   841
    "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
   842
     The date components are taken from today."
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   843
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   844
    ^ self asLocalTimestamp
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   845
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   846
    "
8994
cbf9e75584fe asTimeStamp -> asTimestamp for AbstractTime protocol compatibility
Stefan Vogel <sv@exept.de>
parents: 8796
diff changeset
   847
      Time now asTimestamp
8249
bdcae1232e6d Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 8231
diff changeset
   848
    "
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   849
!
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   850
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   851
asUtcTimestamp
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   852
    "return an UtcTimestamp object from the receiver.
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   853
     So I am interpreted as a Time in the UTC zone.
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   854
     The date components are taken from today."
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   855
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   856
    ^ self asLocalTimestamp asUtcTimestamp.
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   857
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   858
    "
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   859
     Time now asTimestamp       -> 2017-07-17 14:08:22
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   860
     Time now asLocalTimestamp  -> 2017-07-17 14:08:24
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   861
     Time now asUtcTimestamp    -> 2017-07-17 12:08:27Z
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
   862
    "
22038
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   863
5e9eceb76859 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20818
diff changeset
   864
    "Modified (comment): / 17-07-2017 / 14:09:45 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   865
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
   866
24118
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   867
!Time methodsFor:'double dispatching'!
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   868
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   869
differenceFromTimestamp:aTimestamp
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   870
    "return the time difference as a timeDuration instance.
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   871
     Use only the time part of aTimestamp (so interpret it as a time today)."
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   872
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   873
    ^ TimeDuration basicNew setMilliseconds:aTimestamp asTime getMilliseconds - self getMilliseconds.
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   874
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   875
    "
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   876
        Time nowWithMilliseconds differenceFromTimestamp:Timestamp now.
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   877
        Time now differenceFromTimestamp:Time now + 1 seconds
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   878
    "
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   879
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   880
    "Created: / 27-07-2018 / 11:23:37 / Stefan Vogel"
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   881
    "Modified (comment): / 08-05-2019 / 13:06:35 / Claus Gittinger"
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   882
! !
02d39aaca894 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23790
diff changeset
   883
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   884
!Time methodsFor:'printing & storing'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   885
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   886
print12HourFormatOn:aStream
11151
61a33963c219 comments
Claus Gittinger <cg@exept.de>
parents: 10933
diff changeset
   887
    "append a human readable printed representation of the receiver to aStream.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   888
     Format is hh:mm:ss am/pm (i.e. 12-hour american format)."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   889
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   890
    ^ self
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   891
	printOn:aStream
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   892
	format:(self class formatString12us)
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   893
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   894
"/    |h m s ampm|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   895
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   896
"/    h := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   897
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   898
"/    "/ 0 -> 12 am
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   899
"/    "/ 12 -> 12 pm
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   900
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   901
"/    h // 12 == 0 ifTrue:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   902
"/        ampm := ' am'.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   903
"/    ] ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   904
"/        ampm := ' pm'.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   905
"/    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   906
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   907
"/    h == 0 ifFalse:[
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   908
"/        h := h - 1 \\ 12 + 1.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   909
"/    ].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   910
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   911
"/    h printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   912
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   913
"/    m := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   914
"/    (m < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   915
"/    m printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   916
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   917
"/    s := self seconds.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   918
"/    (s < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   919
"/    s printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   920
"/    aStream nextPutAll:ampm
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   921
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   922
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   923
     Time now print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   924
     (Time now subtractHours:12) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   925
     (Time hour:24 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   926
     (Time hour:12 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   927
     (Time hour:0 minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   928
     0 to:24 do:[:h |
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   929
	 (Time hour:h minutes:0 seconds:0) print12HourFormatOn:Transcript. Transcript cr
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   930
     ]
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   931
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   932
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   933
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   934
print24HourFormatOn:aStream
11151
61a33963c219 comments
Claus Gittinger <cg@exept.de>
parents: 10933
diff changeset
   935
    "append a human readable printed representation of the receiver to aStream.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   936
     Format is hh:mm:ss (i.e. 24-hour european format)."
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   937
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   938
    ^ self
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   939
	printOn:aStream
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
   940
	format:(self class formatString24).
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   941
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   942
"/    |h m s|
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   943
"/
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   944
"/    h := self hours.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   945
"/    (h < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   946
"/    h printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   947
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   948
"/    m := self minutes.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   949
"/    (m < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   950
"/    m printOn:aStream.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   951
"/    aStream nextPut:$:.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   952
"/    s := self seconds.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   953
"/    (s < 10) ifTrue:[aStream nextPut:$0].
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   954
"/    s printOn:aStream
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   955
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   956
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   957
     Time now print24HourFormatOn:Transcript. Transcript cr
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   958
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   959
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
   960
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   961
printAsUTCIso8601FormatOn:aStream
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   962
    "prints the receiver as UTC time"
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   963
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   964
    Timestamp timestampISO8601Builder
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   965
        print:self compact:false
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   966
        asLocal:false asUTC:true withMilliseconds:true
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   967
        timeSeparator:$T timeOnly:true
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   968
        on:aStream
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   969
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   970
    "
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   971
     Time now printString           -> '04:23:33 PM'
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   972
     Time now printStringIso8601    -> 'T16:23:39'  (notice: this is local time)
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   973
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   974
     Time now printAsUTCIso8601FormatOn:Transcript. Transcript cr.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   975
     Time now printIso8601FormatOn:Transcript. Transcript cr. 
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   976
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   977
    "
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   978
!
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
   979
23021
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   980
printIso8601CompressedOn:aStream
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   981
    "prints the receiver as local time"
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   982
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   983
    Timestamp timestampISO8601Builder
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   984
        print:self compact:true
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   985
        asLocal:true asUTC:false withMilliseconds:true
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   986
        timeSeparator:$T timeOnly:true
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   987
        on:aStream
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   988
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   989
    "
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   990
     Time now printString           -> '04:23:33 PM'
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   991
     Time now printStringIso8601    -> 'T16:23:39'  (notice: this is local time)
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   992
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   993
     Time now printAsUTCIso8601FormatOn:Transcript. Transcript cr.
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   994
     Time now printIso8601FormatOn:Transcript. Transcript cr. 
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   995
    "
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   996
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   997
    "Created: / 25-05-2018 / 12:06:35 / Claus Gittinger"
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   998
!
84cc05d2dde8 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 22886
diff changeset
   999
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1000
printIso8601FormatOn:aStream
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1001
    "prints the receiver as local time"
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1002
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1003
    Timestamp timestampISO8601Builder
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1004
        print:self compact:false
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1005
        asLocal:true asUTC:false withMilliseconds:true
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1006
        timeSeparator:$T timeOnly:true
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1007
        on:aStream
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1008
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1009
    "
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1010
     Time now printString           -> '04:23:33 PM'
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1011
     Time now printStringIso8601    -> 'T16:23:39'  (notice: this is local time)
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1012
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1013
     Time now printAsUTCIso8601FormatOn:Transcript. Transcript cr.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1014
     Time now printIso8601FormatOn:Transcript. Transcript cr. 
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
  1015
     Time now printIso8601CompressedOn:Transcript. Transcript cr. 
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1016
    "
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1017
!
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1018
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1019
printOn:aStream
11151
61a33963c219 comments
Claus Gittinger <cg@exept.de>
parents: 10933
diff changeset
  1020
    "append a human readable printed representation of the receiver to aStream.
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1021
     The format is suitable for a human - not meant to be read back.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1022
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1023
     Format is hh:mm:ss either in 12-hour or 24-hour format.
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1024
     depending on the setting of LanguageTerritory.
17162
682a35f6f035 class: Time
Claus Gittinger <cg@exept.de>
parents: 17141
diff changeset
  1025
     I don't know what ST-80 does here (12-hour format ?)"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1026
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1027
    |format|
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1028
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1029
    format := (self milliseconds = 0)
17162
682a35f6f035 class: Time
Claus Gittinger <cg@exept.de>
parents: 17141
diff changeset
  1030
                    ifTrue:[self class defaultFormatString]
682a35f6f035 class: Time
Claus Gittinger <cg@exept.de>
parents: 17141
diff changeset
  1031
                    ifFalse:[self class defaultFormatStringWithMilliseconds].
13213
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
  1032
    ^ self
17162
682a35f6f035 class: Time
Claus Gittinger <cg@exept.de>
parents: 17141
diff changeset
  1033
        printOn:aStream
682a35f6f035 class: Time
Claus Gittinger <cg@exept.de>
parents: 17141
diff changeset
  1034
        format:format
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1035
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1036
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1037
     Time now printOn:Transcript. Transcript cr
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1038
     Time now printString
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1039
     Time now printStringIso8601
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1040
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1041
13213
d37c29bad3da added: #defaultFormatString
Claus Gittinger <cg@exept.de>
parents: 12829
diff changeset
  1042
    "Modified: / 16-01-2011 / 11:27:24 / cg"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1043
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1044
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1045
printString12HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1046
    "return a printed representation in 12 hour format"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1047
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1048
    ^ self printStringFormat:(self class formatString12us)
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1049
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1050
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1051
     Time now printString12HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1052
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1053
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1054
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1055
printString24HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1056
    "return a printed representation in 24 hour format"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1057
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1058
    ^ self printStringFormat:(self class formatString24)
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1059
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1060
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1061
     Time now printString24HourFormat
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1062
    "
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1063
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1064
!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1065
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1066
shortPrintString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1067
    "dummy - for now"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1068
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1069
    ^ self printString
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1070
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1071
    "Created: 20.6.1997 / 17:17:01 / cg"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1072
! !
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1073
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1074
!Time methodsFor:'private'!
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1075
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1076
fromOSTime:osTime
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1077
    "set my time in the local timezone, given an osTime"
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1078
7513
8a39ab36a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7293
diff changeset
  1079
    |i|
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1080
7513
8a39ab36a0f0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7293
diff changeset
  1081
    i := OperatingSystem computeTimeAndDateFrom:osTime.
7740
5a9d544b8906 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 7733
diff changeset
  1082
    self setHours:(i hours) minutes:(i minutes) seconds:(i seconds)
6164
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1083
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1084
    "Modified: 1.7.1996 / 15:21:06 / cg"
8335251d4cf9 *** empty log message ***
md
parents: 6163
diff changeset
  1085
!
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
  1086
16940
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1087
fromOSTimeWithMilliseconds:osTime
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1088
    "set my time in the local timezone, given an osTime"
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1089
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1090
    |i|
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1091
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1092
    i := OperatingSystem computeTimeAndDateFrom:osTime.
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1093
    self setHours:(i hours) minutes:(i minutes) seconds:(i seconds) milliseconds:(i milliseconds)
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1094
!
38fa652b86a8 class: Time
Claus Gittinger <cg@exept.de>
parents: 16937
diff changeset
  1095
13235
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1096
fromUtcOSTime:osTime
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1097
    "set my time in the local timezone, given an osTime"
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1098
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1099
    |i|
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1100
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1101
    i := OperatingSystem computeUTCTimeAndDateFrom:osTime.
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1102
    self setHours:(i hours) minutes:(i minutes) seconds:(i seconds)
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1103
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1104
    "Modified: 1.7.1996 / 15:21:06 / cg"
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1105
!
Stefan Vogel <sv@exept.de>
parents: 13213
diff changeset
  1106
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1107
fromUtcOSTimeWithMilliseconds:osTime
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1108
    "set my time in the local timezone, given an osTime"
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1109
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1110
    |i|
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1111
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1112
    i := OperatingSystem computeUTCTimeAndDateFrom:osTime.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1113
    self setHours:(i hours) minutes:(i minutes) seconds:(i seconds) milliseconds:(i milliseconds)
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1114
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1115
    "Modified: 1.7.1996 / 15:21:06 / cg"
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1116
!
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1117
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1118
getMilliseconds
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1119
    "return the number of milliseconds since midnight.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1120
     Notice that the receiver may or may not have millisecond resolution,
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1121
     depending on whether it was created by Time now or by Time nowWithMilliseconds.
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1122
     Notice: 
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1123
        does not include any timezone info (in contrast to Timestamp),
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1124
        so this always represent a time depending on the context (usually: local)
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1125
     Notice:
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1126
        beacuse of that, always use Timestamps for comparisons."
6046
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
  1127
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1128
    ^ timeEncoding
22839
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1129
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1130
    "
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1131
     Time now getMilliseconds
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1132
     Time nowWithMilliseconds getMilliseconds
ff149d1b48fb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22809
diff changeset
  1133
    "
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1134
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1135
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
  1136
getSeconds
22282
fb6c49f010a1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22038
diff changeset
  1137
    "return the number of (truncated) seconds since midnight"
6046
f95c62b9831d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6045
diff changeset
  1138
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1139
    ^ timeEncoding // 1000
22282
fb6c49f010a1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22038
diff changeset
  1140
fb6c49f010a1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22038
diff changeset
  1141
    "Modified (comment): / 21-09-2017 / 18:50:16 / cg"
275
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
  1142
!
a76029ddaa98 *** empty log message ***
claus
parents: 241
diff changeset
  1143
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1144
setHours:h minutes:m seconds:s
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1145
    "set my time given individual values"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1146
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1147
    self setSeconds:(((h\\24) * 60 * 60 ) + (m * 60) + s).
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1148
!
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1149
16937
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
  1150
setHours:h minutes:m seconds:s milliseconds:ms
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
  1151
    "set my time given individual values"
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
  1152
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
  1153
    self setMilliseconds:((((h\\24) * 60 * 60 ) + (m * 60) + s) * 1000) + ms.
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
  1154
!
faae893ed94b class: Time
Claus Gittinger <cg@exept.de>
parents: 16933
diff changeset
  1155
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1156
setMilliseconds:millis
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1157
    "set my time given milliseconds since midnight.
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1158
     Notice the modulo operations here - there cannot be a time beyond 24hours
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1159
     (use TimeDuration, if you need that)."
3477
ac8613ab02c9 fixed am/pm printing
Claus Gittinger <cg@exept.de>
parents: 2706
diff changeset
  1160
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1161
    millis < 0 ifTrue:[
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1162
	timeEncoding := (24 * 3600 * 1000) - (millis negated \\ (24 * 3600 * 1000))
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1163
    ] ifFalse:[
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1164
	timeEncoding := millis
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1165
    ].
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1166
    timeEncoding >= (24 * 3600 * 1000) ifTrue:[
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1167
	timeEncoding := timeEncoding \\ (24 * 3600 * 1000).
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1168
    ]
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1169
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1170
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1171
     Time basicNew setSeconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1172
     Time fromSeconds:3601
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1173
     Time now seconds
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1174
     Time now timeEncoding
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1175
     (Time now addDays:5) seconds
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1176
     (Time now addDays:5) timeEncoding
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1177
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1178
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1179
22886
a303a0c8a8c9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22839
diff changeset
  1180
setMilliseconds:millis additionalPicoseconds:ignoredPicos
a303a0c8a8c9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22839
diff changeset
  1181
    "for protocol compatibility with timestamp.
a303a0c8a8c9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22839
diff changeset
  1182
     However, the picos are ignored here"
a303a0c8a8c9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22839
diff changeset
  1183
a303a0c8a8c9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22839
diff changeset
  1184
    ^ self setMilliseconds:millis
a303a0c8a8c9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22839
diff changeset
  1185
!
a303a0c8a8c9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22839
diff changeset
  1186
6904
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1187
setSeconds:secs
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1188
    "set my time given seconds since midnight.
9441
bbc70993779b typo in comment
Stefan Vogel <sv@exept.de>
parents: 9061
diff changeset
  1189
     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
  1190
     (use TimeDuration, if you need that)."
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1191
16933
dcf3e0e47852 class: Time
Claus Gittinger <cg@exept.de>
parents: 13632
diff changeset
  1192
    self setMilliseconds:secs * 1000
6904
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1193
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1194
    "
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1195
     Time basicNew setSeconds:0
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1196
     Time fromSeconds:3601
6904
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1197
     Time now seconds
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1198
     Time now timeEncoding
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1199
     (Time now addDays:5) seconds
6904
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1200
     (Time now addDays:5) timeEncoding
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1201
    "
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1202
!
680e7d97de38 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6903
diff changeset
  1203
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1204
timeEncoding
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1205
    "the internal encoding is stricktly private,
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1206
     and should not be used outside."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1207
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1208
    ^ timeEncoding
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1209
!
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1210
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1211
timeEncoding:encoding
17066
983f61f73c8f wrong parenthesis (fraction asInteger)
Claus Gittinger <cg@exept.de>
parents: 16985
diff changeset
  1212
    "the internal encoding is stricktly private,
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1213
     and should not be used outside."
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1214
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1215
    timeEncoding := encoding
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1216
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1217
25221
4fcb818b33a1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24118
diff changeset
  1218
22809
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1219
!Time methodsFor:'visiting'!
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1220
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1221
acceptVisitor:aVisitor with:aParameter
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1222
    "dispatch for visitor pattern; send #visitTime:with: to aVisitor"
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1223
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1224
    ^ aVisitor visitTime:self with:aParameter
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1225
! !
89897abfad56 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22282
diff changeset
  1226
6165
0ac589c3d92a comparing & hash fixed (to work with TimeEncoding)
md
parents: 6164
diff changeset
  1227
!Time class methodsFor:'documentation'!
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
  1228
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 569
diff changeset
  1229
version
19848
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
  1230
    ^ '$Header$'
12728
31ba8fef2678 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11809
diff changeset
  1231
!
31ba8fef2678 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11809
diff changeset
  1232
31ba8fef2678 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11809
diff changeset
  1233
version_CVS
19848
5418481e516b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18456
diff changeset
  1234
    ^ '$Header$'
241
6f30be88e314 *** empty log message ***
claus
parents: 239
diff changeset
  1235
! !
17136
0ef1bb251905 class: Time
Claus Gittinger <cg@exept.de>
parents: 17066
diff changeset
  1236