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