TimeDuration.st
author Stefan Vogel <sv@exept.de>
Fri, 18 Jan 2008 20:40:51 +0100
changeset 1922 be14f1a04953
parent 1905 ec30ff95406a
child 1989 fbaeabdda6bd
permissions -rw-r--r--
#add:beforeIndex: - make immune against redefinition of #add: using #add:beforeIndex in subclasses (and leading to recursion).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
989
9bef129296da initial checkin
md
parents:
diff changeset
     1
"
9bef129296da initial checkin
md
parents:
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
9bef129296da initial checkin
md
parents:
diff changeset
     3
	      All Rights Reserved
9bef129296da initial checkin
md
parents:
diff changeset
     4
9bef129296da initial checkin
md
parents:
diff changeset
     5
 This software is furnished under a license and may be used
9bef129296da initial checkin
md
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
9bef129296da initial checkin
md
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
9bef129296da initial checkin
md
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
9bef129296da initial checkin
md
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
9bef129296da initial checkin
md
parents:
diff changeset
    10
 hereby transferred.
9bef129296da initial checkin
md
parents:
diff changeset
    11
"
9bef129296da initial checkin
md
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
9bef129296da initial checkin
md
parents:
diff changeset
    13
9bef129296da initial checkin
md
parents:
diff changeset
    14
Time subclass:#TimeDuration
9bef129296da initial checkin
md
parents:
diff changeset
    15
	instanceVariableNames:''
1902
sr
parents: 1901
diff changeset
    16
	classVariableNames:'TimeDurationZero'
989
9bef129296da initial checkin
md
parents:
diff changeset
    17
	poolDictionaries:''
1332
3459071d37c8 Category change
Stefan Vogel <sv@exept.de>
parents: 1133
diff changeset
    18
	category:'Magnitude-Time'
989
9bef129296da initial checkin
md
parents:
diff changeset
    19
!
9bef129296da initial checkin
md
parents:
diff changeset
    20
9bef129296da initial checkin
md
parents:
diff changeset
    21
!TimeDuration class methodsFor:'documentation'!
9bef129296da initial checkin
md
parents:
diff changeset
    22
9bef129296da initial checkin
md
parents:
diff changeset
    23
copyright
9bef129296da initial checkin
md
parents:
diff changeset
    24
"
9bef129296da initial checkin
md
parents:
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
9bef129296da initial checkin
md
parents:
diff changeset
    26
	      All Rights Reserved
9bef129296da initial checkin
md
parents:
diff changeset
    27
9bef129296da initial checkin
md
parents:
diff changeset
    28
 This software is furnished under a license and may be used
9bef129296da initial checkin
md
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
9bef129296da initial checkin
md
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
9bef129296da initial checkin
md
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
9bef129296da initial checkin
md
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
9bef129296da initial checkin
md
parents:
diff changeset
    33
 hereby transferred.
9bef129296da initial checkin
md
parents:
diff changeset
    34
"
9bef129296da initial checkin
md
parents:
diff changeset
    35
!
9bef129296da initial checkin
md
parents:
diff changeset
    36
9bef129296da initial checkin
md
parents:
diff changeset
    37
documentation
9bef129296da initial checkin
md
parents:
diff changeset
    38
"
9bef129296da initial checkin
md
parents:
diff changeset
    39
"
9bef129296da initial checkin
md
parents:
diff changeset
    40
! !
9bef129296da initial checkin
md
parents:
diff changeset
    41
9bef129296da initial checkin
md
parents:
diff changeset
    42
!TimeDuration class methodsFor:'instance creation'!
9bef129296da initial checkin
md
parents:
diff changeset
    43
1555
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    44
days:d 
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    45
    "return a new TimeDuration representing a duration of d days."
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    46
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    47
    ^ self hours:(d*24) minutes:0
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    48
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    49
    "
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    50
     TimeDuration days:1  
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    51
    "
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    52
!
9bc5802bbbf3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1545
diff changeset
    53
1891
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    54
fromMilliseconds:millisecondsInterval
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    55
    "redefined to disable wrapping at 24hours."
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    56
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    57
    ^ self new setMilliseconds:millisecondsInterval
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    58
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    59
    "
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    60
     TimeDuration fromMilliseconds:500  
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    61
    "
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    62
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    63
    "Created: / 18-07-2007 / 13:56:25 / cg"
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    64
!
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
    65
1507
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    66
fromMinutes:minutesInterval
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    67
    ^ self new setSeconds:(minutesInterval * 60)
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    68
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    69
    "
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    70
     TimeDuration fromMinutes:120  
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    71
    "
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    72
!
6d7818e55549 instance creation
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    73
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
    74
fromSeconds:secondsInterval
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
    75
    "redefined to disable wrapping at 24hours."
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
    76
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
    77
    ^ self new setSeconds:secondsInterval
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
    78
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
    79
    "
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
    80
     TimeDuration fromSeconds:3600  
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
    81
    "
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
    82
!
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
    83
1889
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    84
hours:h
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    85
    "return a new TimeDuration representing a duration of h hours.
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    86
     See also Time now / Date today / Timestamp now."
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    87
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    88
    ^ self basicNew setHours:h minutes:0 seconds:0 milliseconds:0
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    89
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    90
    "
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    91
     TimeDuration hours:2 
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    92
     TimeDuration hours:100  
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    93
    "
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    94
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    95
    "Created: / 14-07-2007 / 18:15:51 / cg"
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    96
!
e17a79ef2e4c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1555
diff changeset
    97
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
    98
hours:h minutes:m
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
    99
    "return a new TimeDuration representing a duration of h hours and m minutes.
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   100
     See also Time now / Date today / Timestamp now."
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   101
1545
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   102
    ^ self basicNew setHours:h minutes:m seconds:0 milliseconds:0
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   103
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   104
    "
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   105
     TimeDuration hours:2 minutes:33 
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   106
     TimeDuration hours:100 minutes:33  
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   107
    "
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   108
!
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   109
989
9bef129296da initial checkin
md
parents:
diff changeset
   110
hours:h minutes:m seconds:s millis:millis
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   111
    "return a new TimeDuration representing a duration of h hours, m minutes, s seconds and millis milliseconds.
1433
47729d4283ef Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 1419
diff changeset
   112
     See also Time now / Date today / Timestamp now."
989
9bef129296da initial checkin
md
parents:
diff changeset
   113
1545
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   114
    self obsoleteMethodWarning:'use hours:minutes:seconds:milliseconds:'.
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   115
    ^ self hours:h minutes:m seconds:s milliseconds:millis
989
9bef129296da initial checkin
md
parents:
diff changeset
   116
9bef129296da initial checkin
md
parents:
diff changeset
   117
    "
1545
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   118
     TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123  
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   119
     TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123  
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   120
    "
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   121
!
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   122
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   123
hours:h minutes:m seconds:s milliseconds:millis
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   124
    "return a new TimeDuration representing a duration of h hours, m minutes, s seconds and millis milliseconds.
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   125
     See also Time now / Date today / Timestamp now."
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   126
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   127
    ^ self basicNew 
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   128
        setHours:h minutes:m seconds:s milliseconds:millis
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   129
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   130
    "
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   131
     TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123  
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   132
     TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123  
989
9bef129296da initial checkin
md
parents:
diff changeset
   133
    "
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   134
!
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   135
1892
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   136
minutes:m
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   137
    "return a new TimeDuration representing a duration of m minutes.
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   138
     See also Time now / Date today / Timestamp now."
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   139
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   140
    ^ self basicNew setHours:0 minutes:m seconds:0 milliseconds:0
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   141
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   142
    "
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   143
     TimeDuration minutes:2 
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   144
    "
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   145
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   146
    "Created: / 06-08-2007 / 15:32:42 / cg"
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   147
!
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   148
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   149
readFrom:aStringOrStream onError:exceptionBlock
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   150
    "return a new TimeDuration, reading a printed representation from aStream.
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   151
     The format is [n 'd'] [n 'h'] [n 'm'] [n 's']"
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   152
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   153
    ^ [
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   154
        |seconds millis str val fraction uIdx unit unitChar1 unitChar2|
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   155
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   156
        str := aStringOrStream readStream.
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   157
        seconds := 0.
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   158
        millis := 0.
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   159
        [
1897
d13a5cbd9250 reading from empty string fixed
Claus Gittinger <cg@exept.de>
parents: 1896
diff changeset
   160
            val := Integer readFrom:str onError:nil.
d13a5cbd9250 reading from empty string fixed
Claus Gittinger <cg@exept.de>
parents: 1896
diff changeset
   161
            val isNil ifTrue:[^ exceptionBlock value].
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   162
            str peek == $. ifTrue:[
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   163
                str next.
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   164
                fraction := Number readMantissaFrom:str radix:10.
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   165
                val := val + fraction.
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   166
            ].
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   167
            str skipSeparators.
1894
8bf137acc445 if no unit is given in the readString, assume seconds.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   168
            str atEnd ifTrue:[
8bf137acc445 if no unit is given in the readString, assume seconds.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   169
                "/ no unit given - assume seconds
8bf137acc445 if no unit is given in the readString, assume seconds.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   170
                ^ self fromSeconds:val.
8bf137acc445 if no unit is given in the readString, assume seconds.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   171
                "/ ^ exceptionBlock value
8bf137acc445 if no unit is given in the readString, assume seconds.
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   172
            ].
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   173
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   174
            unitChar1 := str next.
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   175
            uIdx := #($d $h $m $s) indexOf:unitChar1.
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   176
            uIdx == 0 ifTrue:[^ exceptionBlock value].
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   177
            (unitChar1 == $m and:[str peek == $s]) ifTrue:[
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   178
                str next.
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   179
                millis := millis + val.
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   180
            ] ifFalse:[
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   181
                unit := #(86400 "24*60*60"
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   182
                          3600
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   183
                          60
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   184
                          1 ) at:uIdx.
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   185
                seconds := seconds + (unit * val).
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   186
            ].
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   187
            str skipSeparators.
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   188
            str atEnd
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   189
        ] whileFalse.
1891
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   190
        self fromMilliseconds:(seconds*1000+millis) rounded asInteger.
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   191
    ] on:Error do:exceptionBlock.
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   192
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   193
    "
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   194
     TimeDuration readFrom:'1h'      
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   195
     TimeDuration readFrom:'1h 35m'     
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   196
     TimeDuration readFrom:'25h'     
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   197
     TimeDuration readFrom:'3d'     
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   198
     TimeDuration readFrom:'120s'     
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   199
     TimeDuration readFrom:'1500ms    
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   200
     TimeDuration readFrom:'3ms'     
1508
2b0ee9160c5a instance creation: readFrom
Claus Gittinger <cg@exept.de>
parents: 1507
diff changeset
   201
    "
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   202
1897
d13a5cbd9250 reading from empty string fixed
Claus Gittinger <cg@exept.de>
parents: 1896
diff changeset
   203
    "Modified: / 08-10-2007 / 16:41:48 / cg"
1892
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   204
!
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   205
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   206
seconds:s
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   207
    "return a new TimeDuration representing a duration of s seconds.
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   208
     See also Time now / Date today / Timestamp now."
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   209
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   210
    ^ self basicNew setHours:0 minutes:0 seconds:s milliseconds:0
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   211
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   212
    "
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   213
     TimeDuration seconds:2 
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   214
    "
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   215
9a7062768503 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1891
diff changeset
   216
    "Created: / 06-08-2007 / 15:32:21 / cg"
989
9bef129296da initial checkin
md
parents:
diff changeset
   217
! !
9bef129296da initial checkin
md
parents:
diff changeset
   218
1902
sr
parents: 1901
diff changeset
   219
!TimeDuration class methodsFor:'class initialization'!
sr
parents: 1901
diff changeset
   220
sr
parents: 1901
diff changeset
   221
initialize
sr
parents: 1901
diff changeset
   222
    TimeDurationZero isNil ifTrue:[
sr
parents: 1901
diff changeset
   223
        TimeDurationZero := self seconds:0.
sr
parents: 1901
diff changeset
   224
    ]
sr
parents: 1901
diff changeset
   225
! !
sr
parents: 1901
diff changeset
   226
sr
parents: 1901
diff changeset
   227
!TimeDuration class methodsFor:'constants'!
sr
parents: 1901
diff changeset
   228
sr
parents: 1901
diff changeset
   229
zero
sr
parents: 1901
diff changeset
   230
    "return the neutral element for addition (0s)"
sr
parents: 1901
diff changeset
   231
sr
parents: 1901
diff changeset
   232
    ^ TimeDurationZero
sr
parents: 1901
diff changeset
   233
sr
parents: 1901
diff changeset
   234
    "Modified: 18.7.1996 / 12:26:12 / cg"
sr
parents: 1901
diff changeset
   235
! !
sr
parents: 1901
diff changeset
   236
989
9bef129296da initial checkin
md
parents:
diff changeset
   237
!TimeDuration class methodsFor:'format strings'!
9bef129296da initial checkin
md
parents:
diff changeset
   238
9bef129296da initial checkin
md
parents:
diff changeset
   239
formatString12us
9bef129296da initial checkin
md
parents:
diff changeset
   240
    "return the format string used to format US times (and other areas)"
9bef129296da initial checkin
md
parents:
diff changeset
   241
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   242
    ^ '%h:%m:%s.%i'
989
9bef129296da initial checkin
md
parents:
diff changeset
   243
!
9bef129296da initial checkin
md
parents:
diff changeset
   244
9bef129296da initial checkin
md
parents:
diff changeset
   245
formatString24
9bef129296da initial checkin
md
parents:
diff changeset
   246
    "return the format string used to format european times (and other areas)"
9bef129296da initial checkin
md
parents:
diff changeset
   247
9bef129296da initial checkin
md
parents:
diff changeset
   248
    ^ '%h:%m:%s.%i'
9bef129296da initial checkin
md
parents:
diff changeset
   249
! !
9bef129296da initial checkin
md
parents:
diff changeset
   250
9bef129296da initial checkin
md
parents:
diff changeset
   251
!TimeDuration methodsFor:'accessing'!
9bef129296da initial checkin
md
parents:
diff changeset
   252
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   253
days
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   254
    ^ timeEncoding // 1000 // 3600 // 24
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   255
!
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   256
989
9bef129296da initial checkin
md
parents:
diff changeset
   257
milliseconds
9bef129296da initial checkin
md
parents:
diff changeset
   258
    ^ timeEncoding \\ 1000
9bef129296da initial checkin
md
parents:
diff changeset
   259
! !
9bef129296da initial checkin
md
parents:
diff changeset
   260
1896
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   261
!TimeDuration methodsFor:'arithmetic'!
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   262
1900
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   263
* aNumber
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   264
    "return a new timeDuration"
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   265
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   266
    ^ self species basicNew 
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   267
        setMilliseconds:(self getMilliseconds * aNumber) asInteger
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   268
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   269
    "
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   270
     (TimeDuration fromString:'10s') * 5
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   271
    "
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   272
!
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   273
1896
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   274
+ aTimeDurationOrNumberOfSeconds
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   275
    "return a new timeDuration"
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   276
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   277
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   278
        ^ self species basicNew 
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   279
            setMilliseconds:(self getMilliseconds + (aTimeDurationOrNumberOfSeconds * 1000) asInteger)
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   280
    ].
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   281
    ^ self species basicNew
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   282
        setMilliseconds:(self getMilliseconds + aTimeDurationOrNumberOfSeconds getMilliseconds)
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   283
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   284
    "Created: / 04-10-2007 / 14:12:40 / cg"
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   285
!
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   286
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   287
- aTimeDurationOrNumberOfSeconds
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   288
    "return a new timeDuration"
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   289
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   290
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   291
        ^ self species basicNew 
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   292
            setMilliseconds:(self getMilliseconds - (aTimeDurationOrNumberOfSeconds * 1000) asInteger)
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   293
    ].
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   294
    ^ self species basicNew
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   295
        setMilliseconds:(self getMilliseconds - aTimeDurationOrNumberOfSeconds getMilliseconds)
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   296
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   297
    "Created: / 04-10-2007 / 14:12:29 / cg"
1900
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   298
!
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   299
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   300
/ aTimeDurationOrNumberOfSeconds
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   301
    "return a new timeDuration"
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   302
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   303
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   304
        ^ self species basicNew 
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   305
            setMilliseconds:(self getMilliseconds / aTimeDurationOrNumberOfSeconds) asInteger
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   306
    ].
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   307
    ^ (self getMilliseconds / aTimeDurationOrNumberOfSeconds getMilliseconds)
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   308
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   309
    "
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   310
     (TimeDuration fromString:'10s') / (TimeDuration fromString:'5s')
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   311
     (TimeDuration fromString:'10s') / 5
d2389262c677 more artihmetic
sr
parents: 1897
diff changeset
   312
    "
1901
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   313
!
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   314
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   315
productFromFraction:aNumber
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   316
    "return a new timeDuration"
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   317
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   318
    ^ self productFromNumber:aNumber
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   319
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   320
    "
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   321
     (TimeDuration fromString:'10s') * 5
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   322
    "
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   323
!
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   324
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   325
productFromNumber:aNumber
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   326
    "return a new timeDuration"
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   327
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   328
    ^ self species basicNew 
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   329
        setMilliseconds:(self getMilliseconds * aNumber) asInteger
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   330
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   331
    "
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   332
     (TimeDuration fromString:'10s') * 5
5e6771205713 more artihmetic
sr
parents: 1900
diff changeset
   333
    "
1896
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   334
! !
fc107aed9bb9 arithmetic on time-durations
Claus Gittinger <cg@exept.de>
parents: 1894
diff changeset
   335
989
9bef129296da initial checkin
md
parents:
diff changeset
   336
!TimeDuration methodsFor:'converting'!
9bef129296da initial checkin
md
parents:
diff changeset
   337
9bef129296da initial checkin
md
parents:
diff changeset
   338
asTime
9bef129296da initial checkin
md
parents:
diff changeset
   339
    "return a Time object from the receiver - thats the receiver."
9bef129296da initial checkin
md
parents:
diff changeset
   340
9bef129296da initial checkin
md
parents:
diff changeset
   341
    ^ Time hours:(self hours) minutes:(self minutes) seconds:(self seconds)
9bef129296da initial checkin
md
parents:
diff changeset
   342
! !
9bef129296da initial checkin
md
parents:
diff changeset
   343
1893
40b42bfb5c51 adding timeDurations to a timeStamp (double dispatch)
sr
parents: 1892
diff changeset
   344
!TimeDuration methodsFor:'double dispatching'!
40b42bfb5c51 adding timeDurations to a timeStamp (double dispatch)
sr
parents: 1892
diff changeset
   345
40b42bfb5c51 adding timeDurations to a timeStamp (double dispatch)
sr
parents: 1892
diff changeset
   346
sumFromTimestamp:aTimestamp
40b42bfb5c51 adding timeDurations to a timeStamp (double dispatch)
sr
parents: 1892
diff changeset
   347
    ^ aTimestamp addMilliseconds:(self getMilliseconds)
40b42bfb5c51 adding timeDurations to a timeStamp (double dispatch)
sr
parents: 1892
diff changeset
   348
! !
40b42bfb5c51 adding timeDurations to a timeStamp (double dispatch)
sr
parents: 1892
diff changeset
   349
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   350
!TimeDuration methodsFor:'printing'!
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   351
1419
cde809955208 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 1332
diff changeset
   352
addPrintBindingsTo:aDictionary language:languageOrNil
cde809955208 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 1332
diff changeset
   353
    "private print support: add bindings for printing to aDictionary.
cde809955208 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 1332
diff changeset
   354
     languageOrNil can only be #en or nil for the current language."
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   355
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   356
    |hoursInDay s|
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   357
1419
cde809955208 print bindings (care for language specifics)
Claus Gittinger <cg@exept.de>
parents: 1332
diff changeset
   358
    super addPrintBindingsTo:aDictionary language:languageOrNil.
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   359
    aDictionary at:$d put:self days.
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   360
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   361
    hoursInDay := self hours \\ 24.
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   362
    aDictionary at:#Hd put:(s := hoursInDay printString).
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   363
    aDictionary at:#hd put:(s leftPaddedTo:2 with:$0).
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   364
!
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   365
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   366
formatForPrinting
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   367
    "Return a format which is suitable for a human - not meant to be read back."
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   368
1905
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   369
    ^ self formatForPrinting:false
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   370
!
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   371
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   372
formatForPrinting:shortFlag
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   373
    "Return a format which is suitable for a human - not meant to be read back.
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   374
     If shortFlag is true, some millisecond-info is ommitted for longer times."
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   375
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   376
    |fmt hours mins secs overAllSeconds millis|
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   377
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   378
    hours := self hours.
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   379
    mins := self minutes.
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   380
    secs := self seconds.
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   381
    millis := self milliseconds.
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   382
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   383
    hours >= 24 ifTrue:[
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   384
        fmt := '%dd %(Hd)h %Mm'.
1510
b6591353cbc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
   385
        secs = 0 ifTrue:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   386
            fmt := '%dd %(Hd)h %Mm'.
1510
b6591353cbc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
   387
            mins = 0 ifTrue:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   388
                fmt := '%dd %(Hd)h'.
1511
1c2927ced290 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1510
diff changeset
   389
                (hours \\ 24) = 0 ifTrue:[
1509
e9463ce3bee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   390
                    fmt := '%dd'.
e9463ce3bee6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1508
diff changeset
   391
                ].
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   392
            ].
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   393
        ].
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   394
    ] ifFalse:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   395
        hours > 0 ifTrue:[
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   396
            fmt := '%Hh %Mm'.
1510
b6591353cbc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
   397
            secs = 0 ifTrue:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   398
                fmt := '%Hh %Mm'.
1510
b6591353cbc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
   399
                mins = 0 ifTrue:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   400
                    fmt := '%Hh'.
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   401
                ].
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   402
            ].
1133
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   403
        ] ifFalse:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   404
            mins > 0 ifTrue:[
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   405
                fmt := '%Mm'.
1510
b6591353cbc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
   406
                secs = 0 ifTrue:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   407
                    fmt := '%Mm'
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   408
                ].
1133
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   409
            ] ifFalse:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   410
                fmt := ''
1133
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   411
            ].
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   412
        ].
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   413
    ].
1510
b6591353cbc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
   414
    ((secs ~= 0) or:[millis ~= 0])ifTrue:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   415
        fmt size ~~ 0 ifTrue:[
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   416
            fmt := fmt , ' '
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   417
        ].
1510
b6591353cbc0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1509
diff changeset
   418
        (millis = 0) ifTrue:[
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   419
            fmt := fmt , '%Ss'
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   420
        ] ifFalse:[
1891
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   421
            secs = 0 ifTrue:[
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   422
                fmt := fmt , '%Ims'
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   423
            ] ifFalse:[
1905
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   424
                shortFlag ifTrue:[
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   425
                    overAllSeconds := self asSeconds.
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   426
                    overAllSeconds > 2 ifTrue:[
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   427
                        overAllSeconds > 10 ifTrue:[
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   428
                            overAllSeconds > 300 ifTrue:[
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   429
                                fmt := fmt , '%Ss'
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   430
                            ] ifFalse:[
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   431
                                fmt := fmt , '%S.%(milli1)s'
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   432
                            ]
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   433
                        ] ifFalse:[
1905
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   434
                            fmt := fmt , '%S.%(milli2)s'
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   435
                        ]
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   436
                    ] ifFalse:[
1905
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   437
                        fmt := fmt , '%S.%is'
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   438
                    ]
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   439
                ] ifFalse:[
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   440
                    fmt := fmt , '%S.%is'
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   441
                ]
1891
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   442
            ]
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   443
        ].
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   444
    ] ifFalse:[
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   445
        fmt isEmpty ifTrue:[
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   446
            fmt := '%Ss'
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   447
        ].
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   448
    ].
1891
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   449
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   450
    ^ fmt.
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   451
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   452
    "
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   453
     TimeDuration hours:0 minutes:0 seconds:0 millis:12       
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   454
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   455
     TimeDuration hours:0 minutes:0 seconds:0 millis:123       
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   456
     TimeDuration hours:0 minutes:0 seconds:10 millis:123       
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   457
     TimeDuration hours:0 minutes:33 seconds:0 millis:123       
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   458
     TimeDuration hours:2 minutes:0 seconds:0 millis:123       
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   459
     TimeDuration hours:2 minutes:33 seconds:0 millis:123       
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   460
     TimeDuration hours:100 minutes:33 seconds:0 millis:123    
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   461
     TimeDuration hours:10000 minutes:33 seconds:0 millis:123    
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   462
     TimeDuration hours:1000000 minutes:33 seconds:0 millis:123    
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   463
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   464
     TimeDuration hours:2 minutes:33 seconds:0 millis:0         
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   465
     TimeDuration hours:2 minutes:0 seconds:0 millis:0          
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   466
     TimeDuration hours:24 minutes:0 seconds:0 millis:0          
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   467
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   468
     (TimeDuration hours:0 minutes:0 seconds:0 millis:123) printStringFormat:'%h:%m:%s'       
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   469
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringFormat:'%h:%m:%s'         
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   470
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   471
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   472
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   473
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   474
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   475
    "
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   476
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   477
    "Modified: / 18-07-2007 / 14:06:17 / cg"
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   478
!
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   479
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   480
printOn:aStream
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   481
    "append a user printed representation of the receiver to aStream.
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   482
     The format is suitable for a human - not meant to be read back."
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   483
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   484
    ^ self
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   485
        printOn:aStream 
1904
12a5da5c091d defaul printFormat
Claus Gittinger <cg@exept.de>
parents: 1902
diff changeset
   486
        format:(self formatForPrinting).
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   487
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   488
    "
1891
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   489
     TimeDuration hours:0 minutes:0 seconds:0 millis:12       
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   490
1133
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   491
     TimeDuration hours:0 minutes:0 seconds:0 millis:123       
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   492
     TimeDuration hours:0 minutes:0 seconds:10 millis:123       
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   493
     TimeDuration hours:0 minutes:33 seconds:0 millis:123       
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   494
     TimeDuration hours:2 minutes:0 seconds:0 millis:123       
1133
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   495
     TimeDuration hours:2 minutes:33 seconds:0 millis:123       
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   496
     TimeDuration hours:100 minutes:33 seconds:0 millis:123    
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   497
     TimeDuration hours:10000 minutes:33 seconds:0 millis:123    
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   498
     TimeDuration hours:1000000 minutes:33 seconds:0 millis:123    
1133
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   499
1506
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   500
     TimeDuration hours:2 minutes:33 seconds:0 millis:0         
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   501
     TimeDuration hours:2 minutes:0 seconds:0 millis:0          
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   502
     TimeDuration hours:24 minutes:0 seconds:0 millis:0          
51bc89e730e5 printing; instance creation
Claus Gittinger <cg@exept.de>
parents: 1433
diff changeset
   503
1133
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   504
     (TimeDuration hours:0 minutes:0 seconds:0 millis:123) printStringFormat:'%h:%m:%s'       
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   505
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringFormat:'%h:%m:%s'         
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   506
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   507
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   508
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   509
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
7f5237057fd4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1123
diff changeset
   510
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   511
    "
1891
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   512
af37298a4b38 printing/storing; ms handling
Claus Gittinger <cg@exept.de>
parents: 1890
diff changeset
   513
    "Modified: / 18-07-2007 / 14:06:17 / cg"
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   514
! !
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   515
989
9bef129296da initial checkin
md
parents:
diff changeset
   516
!TimeDuration methodsFor:'private'!
9bef129296da initial checkin
md
parents:
diff changeset
   517
9bef129296da initial checkin
md
parents:
diff changeset
   518
getMilliseconds
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   519
    "return the number of milliseconds"
989
9bef129296da initial checkin
md
parents:
diff changeset
   520
9bef129296da initial checkin
md
parents:
diff changeset
   521
    ^ timeEncoding
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   522
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   523
    "Modified: / 18-07-2007 / 13:44:33 / cg"
989
9bef129296da initial checkin
md
parents:
diff changeset
   524
!
9bef129296da initial checkin
md
parents:
diff changeset
   525
9bef129296da initial checkin
md
parents:
diff changeset
   526
getSeconds
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   527
    "return the number of seconds"
989
9bef129296da initial checkin
md
parents:
diff changeset
   528
9bef129296da initial checkin
md
parents:
diff changeset
   529
    ^ timeEncoding // 1000
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   530
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   531
    "Modified: / 18-07-2007 / 13:44:37 / cg"
989
9bef129296da initial checkin
md
parents:
diff changeset
   532
!
9bef129296da initial checkin
md
parents:
diff changeset
   533
9bef129296da initial checkin
md
parents:
diff changeset
   534
setHours:h minutes:m seconds:s millis:millis
9bef129296da initial checkin
md
parents:
diff changeset
   535
    "set my time given individual values"
9bef129296da initial checkin
md
parents:
diff changeset
   536
1545
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   537
    self obsoleteMethodWarning:'use setHours:minutes:seconds:milliseconds:'.
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   538
    self setHours:h minutes:m seconds:s milliseconds:millis.
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   539
!
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   540
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   541
setHours:h minutes:m seconds:s milliseconds:millis
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   542
    "set my time given individual values"
36cf17510eaa *millis: interface is obsolete
Claus Gittinger <cg@exept.de>
parents: 1511
diff changeset
   543
1028
5ca34e5c38b2 fixes for durations > 24h
Claus Gittinger <cg@exept.de>
parents: 989
diff changeset
   544
    self setMilliseconds:((h * 60 * 60 ) + (m * 60) + s) * 1000 + millis.
989
9bef129296da initial checkin
md
parents:
diff changeset
   545
!
9bef129296da initial checkin
md
parents:
diff changeset
   546
9bef129296da initial checkin
md
parents:
diff changeset
   547
setMilliseconds:millis
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   548
    "set my duration given milliseconds.
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   549
     Notice that (in contrast to Time), there is no modulu operation here.
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   550
     Duration can be longer than a day"
989
9bef129296da initial checkin
md
parents:
diff changeset
   551
9bef129296da initial checkin
md
parents:
diff changeset
   552
    timeEncoding := millis
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   553
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   554
    "Modified: / 18-07-2007 / 13:44:16 / cg"
989
9bef129296da initial checkin
md
parents:
diff changeset
   555
!
9bef129296da initial checkin
md
parents:
diff changeset
   556
9bef129296da initial checkin
md
parents:
diff changeset
   557
setSeconds:secs
1123
5a407f03c8ce comment
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
   558
    "set my timeduration given seconds.
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   559
     Notice that (in contrast to Time), there is no modulu operation here.
1123
5a407f03c8ce comment
Claus Gittinger <cg@exept.de>
parents: 1028
diff changeset
   560
     Duration can be longer than a day"
989
9bef129296da initial checkin
md
parents:
diff changeset
   561
9bef129296da initial checkin
md
parents:
diff changeset
   562
    self setMilliseconds:(secs * 1000).
1890
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   563
5384a03a9342 comments
Claus Gittinger <cg@exept.de>
parents: 1889
diff changeset
   564
    "Modified: / 18-07-2007 / 13:44:24 / cg"
989
9bef129296da initial checkin
md
parents:
diff changeset
   565
! !
9bef129296da initial checkin
md
parents:
diff changeset
   566
1902
sr
parents: 1901
diff changeset
   567
!TimeDuration methodsFor:'testing'!
sr
parents: 1901
diff changeset
   568
sr
parents: 1901
diff changeset
   569
isZero
sr
parents: 1901
diff changeset
   570
    ^ self = self class zero
sr
parents: 1901
diff changeset
   571
! !
sr
parents: 1901
diff changeset
   572
989
9bef129296da initial checkin
md
parents:
diff changeset
   573
!TimeDuration class methodsFor:'documentation'!
9bef129296da initial checkin
md
parents:
diff changeset
   574
9bef129296da initial checkin
md
parents:
diff changeset
   575
version
1905
ec30ff95406a default printFormat
Claus Gittinger <cg@exept.de>
parents: 1904
diff changeset
   576
    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/TimeDuration.st,v 1.28 2007-10-26 14:07:25 cg Exp $'
989
9bef129296da initial checkin
md
parents:
diff changeset
   577
! !
1902
sr
parents: 1901
diff changeset
   578
sr
parents: 1901
diff changeset
   579
TimeDuration initialize!