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