TimeDuration.st
author Claus Gittinger <cg@exept.de>
Wed, 09 May 2018 18:55:39 +0200
changeset 22843 d6201034cacd
parent 22817 65a92285bb30
child 22856 e8a1e761cdcd
permissions -rw-r--r--
#FEATURE by cg class: TimeDuration class definition added:22 methods removed: #getExactSeconds #picoseconds: comment/format in: #* #addPrintBindingsTo:language: #days #formatForPrinting: #getMilliseconds #hours #milliseconds #minutes #seconds #setSeconds: changed: #asNumber (send #asExactSeconds instead of #getExactSeconds) #picoseconds #setMilliseconds: class: TimeDuration class added: #fromMicroseconds: #fromNanoseconds: #fromPicoseconds: changed: #readFrom:defaultUnit:onError:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22817
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
     1
"{ Encoding: utf8 }"
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
     2
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1989 by Claus Gittinger
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
	      All Rights Reserved
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
16357
db103fed28a4 class: TimeDuration
Claus Gittinger <cg@exept.de>
parents: 16356
diff changeset
    14
"{ Package: 'stx:libbasic' }"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
17388
2d434fd8fec6 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 17059
diff changeset
    16
"{ NameSpace: Smalltalk }"
2d434fd8fec6 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 17059
diff changeset
    17
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Time subclass:#TimeDuration
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    19
	instanceVariableNames:'additionalPicoseconds'
19849
e989f43ce274 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19023
diff changeset
    20
	classVariableNames:'DefaultFormatForPrinting TimeDurationZero'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Magnitude-Time'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!TimeDuration class methodsFor:'documentation'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
copyright
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 1989 by Claus Gittinger
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
	      All Rights Reserved
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
21697
61bb613eeb72 #DOCUMENTATION by mawalch
mawalch
parents: 21506
diff changeset
    43
    Represents a timestamp difference.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    DefaultFormatForPrinting    if non-nil, allows for the variable printFormat to be overwritten
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
!TimeDuration class methodsFor:'instance creation'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
days:d 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    "return a new TimeDuration representing a duration of d days."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    d == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    ^ self hours:(d*24) minutes:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
     TimeDuration days:1  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
days:d hours:h minutes:m seconds:s 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    "return a new TimeDuration representing a duration of d days, h hours, m minutes and s seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    ^ self basicNew 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        setHours:(d*24)+h minutes:m seconds:s milliseconds:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
     TimeDuration days:1  hours:2 minutes:33 seconds:0   
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
     TimeDuration days:4 hours:100 minutes:33 seconds:0   
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
fromHours:hoursInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    "return a new TimeDuration representing a duration of n hours."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    ^ self new setSeconds:(hoursInterval * (60*60))
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
     TimeDuration fromHours:8  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    85
fromMicroseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    86
    "return a new TimeDuration representing a duration of n microseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    87
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    88
    ^ self new setMicroseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    89
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    90
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    91
     TimeDuration fromMicroseconds:500  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    92
     500 microseconds  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    93
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    94
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    95
    "Created: / 18-07-2007 / 13:56:25 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    96
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    97
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
fromMilliseconds:n
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "return a new TimeDuration representing a duration of n milliseconds."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "redefined to disable wrapping at 24hours."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    ^ self new setMilliseconds:n
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
     TimeDuration fromMilliseconds:500  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
     500 milliseconds  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "Created: / 18-07-2007 / 13:56:25 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
fromMinutes:minutesInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    "return a new TimeDuration representing a duration of n minutes."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    ^ self new setSeconds:(minutesInterval * 60)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
     TimeDuration fromMinutes:120  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   122
fromNanoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   123
    "return a new TimeDuration representing a duration of n nanoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   124
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   125
    ^ self new setNanoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   126
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   127
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   128
     TimeDuration fromNanoseconds:500  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   129
     500 nanoseconds  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   130
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   131
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   132
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   133
fromPicoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   134
    "return a new TimeDuration representing a duration of n picoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   135
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   136
    ^ self new setPicoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   137
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   138
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   139
     TimeDuration fromPicoseconds:500  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   140
     500 picoseconds  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   141
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   142
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   143
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
fromSeconds:secondsInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    "return a new TimeDuration representing a duration of n seconds."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    "redefined to disable wrapping at 24hours."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    ^ self new setSeconds:secondsInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
     TimeDuration fromSeconds:3600  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
hours:h
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    "return a new TimeDuration representing a duration of h hours.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    h == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    ^ self basicNew setHours:h minutes:0 seconds:0 milliseconds:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
     TimeDuration hours:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
     TimeDuration hours:100  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    "Created: / 14-07-2007 / 18:15:51 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
hours:h minutes:m seconds:s millis:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    <resource: #obsolete>
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    "return a new TimeDuration representing a duration of h hours, m minutes, s seconds and millis milliseconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    self obsoleteMethodWarning:'use hours:minutes:seconds:milliseconds:'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
    ^ self hours:h minutes:m seconds:s milliseconds:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
     TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
     TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   184
microseconds:microseconds
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   185
    "return a new TimeDuration representing a duration of microseconds microseconds.
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   186
     Currently we do not support this (we round to millis), but maybe later..."
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   187
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   188
    microseconds == 0 ifTrue:[^ TimeDurationZero].
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   189
    ^ self basicNew setMilliseconds:((microseconds / 1000) rounded).
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   190
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   191
    "
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   192
     TimeDuration microseconds:2499 
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   193
     TimeDuration microseconds:2500 
18564
55bd2aa4d56e class: TimeDuration
Claus Gittinger <cg@exept.de>
parents: 17388
diff changeset
   194
     TimeDuration microseconds:12345678900 
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   195
    "
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   196
!
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   197
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
milliseconds:m
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    "return a new TimeDuration representing a duration of m millis.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    m == 0 ifTrue:[^ TimeDurationZero].
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   203
    ^ self basicNew setMilliseconds:m
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
     TimeDuration milliseconds:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
minutes:m
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    "return a new TimeDuration representing a duration of m minutes.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    m == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    ^ self basicNew setHours:0 minutes:m seconds:0 milliseconds:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
     TimeDuration minutes:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
    "Created: / 06-08-2007 / 15:32:42 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   224
readFrom:aStringOrStream defaultUnit:defaultUnitOrNilArg onError:exceptionBlock
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "return a new TimeDuration, reading a printed representation from aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
     The format is either:
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   227
        [n 'yr'] [n 'mon'] [n 'w'] [n 'd'] [n 'h'] [n 'm'] [n 's'] 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   228
                 ([n 'ms'] | [n 'us'] | [n 'ns'] | [n 'ps'])
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
        where 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
            yr -> year
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
            mon -> month
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
            w -> week
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
            d -> day
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
            h -> hour
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
            m -> minutes
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
            s -> seconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   237
            ms -> milliseconds (only one of ms,us,ns or ps can follow)
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   238
            us -> microseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   239
            ns -> nanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   240
            ps -> picoseconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
     or:
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   242
        h:m:s.<ms2>
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   243
        h:m:s.<fract>
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
     The yr and mon specifiers stand for 365d and 30d respectively.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
     If defaultUnitOrNil is non-nil, a plain number is treated as that;
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
     otherwise, a plain number raises an error.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   248
     Individual components may be negative, as in '1h -10m', which gives 50m
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   249
     or the whole duration may be negative, as in '-(1h 10m)'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    ^ [
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   253
        |seconds millis picos restMillis 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   254
         t str val fraction uIdx unit unitChar1 negative defaultUnitOrNil|
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   256
        defaultUnitOrNil := defaultUnitOrNilArg.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
        str := aStringOrStream readStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
        seconds := 0.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
        millis := 0.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   260
        picos := 0.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   261
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   262
        negative := false.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   263
        str peek == $- ifTrue:[
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   264
            str next.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   265
            str peek == $( ifTrue:[
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   266
                |t|
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   267
                str next.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   268
                t := self readFrom:str defaultUnit:defaultUnitOrNil onError:[^ exceptionBlock value].
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   269
                str skipSeparators.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   270
                str peek == $) ifTrue:[
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   271
                    str next.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   272
                    ^ t negated.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   273
                ].
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   274
                ^ exceptionBlock value.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   275
            ].                
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   276
            negative := true.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   277
        ].
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   278
        
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
        [
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
            |nextCh|
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
            val := Integer readFrom:str onError:nil.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
            val isNil ifTrue:[^ exceptionBlock value].
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   284
            negative ifTrue:[ val := val negated. negative := false. ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
            str peek == $: ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
                "/ hour:minutes format
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
                str next.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
                seconds := val*3600.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
                val := Integer readFrom:str onError:nil.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
                val isNil ifTrue:[^ exceptionBlock value].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
                seconds := seconds + (val*60).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
                str peek == $: ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
                    "/ hour:minutes:seconds format
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
                    str next.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
                    val := Integer readFrom:str onError:nil.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
                    val isNil ifTrue:[^ exceptionBlock value].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
                    seconds := seconds + val.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
                    str peek == $. ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
                        "/ hour:minutes:seconds.millis format
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
                        str next.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   301
                        "/ the old code here was wrong in assuming that exactly 3 digits
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   302
                        "/ are coming; thus hh:mm:ss.1 was interpreted as 1ms (instead of 100)
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   303
                        "/ thus: count the zeros...
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   304
                        str peek isDigit ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   305
                            fraction := Number readMantissaFrom:str radix:10.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   306
                            fraction isNil ifTrue:[^ exceptionBlock value].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   307
                            millis := (fraction * 1000) rounded.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   308
                        ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   309
                            millis := 0
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   310
                        ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
                    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
                ^ self fromMilliseconds:(seconds*1000+millis) rounded asInteger.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
            ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   315
            ((str peek == $.) or:[(str peek == $,)]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
                str next.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
                fraction := Number readMantissaFrom:str radix:10.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
                val := val + fraction.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
            str skipSeparators.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
            str atEnd ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
                defaultUnitOrNil isNil ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
                    ^ exceptionBlock value
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
                "/ no unit given - assume defaultUnit
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
                unitChar1 := defaultUnitOrNil.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   327
                "/ can be only used for one number
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   328
                defaultUnitOrNil := nil.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
            ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
                unitChar1 := str next.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
            str atEnd ifFalse:[ 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
                nextCh := str peek
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   337
            "/ milli, micro, nano and pico
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   338
            unitChar1 == $µ ifTrue:[ unitChar1 := $u].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   339
            uIdx := #($m $u $n $p) indexOf:unitChar1.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   340
            ((uIdx ~~ 0) and:[nextCh == $s]) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   341
                unitChar1 == $m ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   342
                    millis := millis + val.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
                ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
                    unit := #(
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   345
                          1000000       "us" 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   346
                          1000          "ns" 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   347
                          1             "ps" 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   348
                          ) at:uIdx-1.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   349
                    picos := (unit * val).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   350
                    millis := picos // (1000 * 1000 * 1000).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   351
                    picos := picos \\ (1000 * 1000 * 1000).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
                ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   353
            ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   354
                uIdx := #($y $w $d $h $m $s) indexOf:unitChar1.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   355
                uIdx == 0 ifTrue:[^ exceptionBlock value].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   356
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   357
                (unitChar1 == $m and:[nextCh == $s]) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   358
                    millis := millis + val.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   359
                ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   360
                    (unitChar1 == $m and:[nextCh == $o]) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   361
                        unit := 2592000 "24*60*60*30"     "mon"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   362
                    ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   363
                        unit := #(
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   364
                                  31536000 "24*60*60*365" "yr"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   365
                                  604800 "24*60*60*7"     "w"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   366
                                  86400  "24*60*60"       "d"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   367
                                  3600                    "h"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   368
                                  60                      "m"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   369
                                  1 ) at:uIdx.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   370
                    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   371
                    seconds := seconds + (unit * val).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   372
                ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
            ].
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   374
            [str atEnd not and:[str peek isSeparator not and:[str peek ~~ $)]]] whileTrue:[ str next].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
            str skipSeparators.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   376
            "/ done when at the end or a $) is to be read
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   377
            str atEnd or:[aStringOrStream isString not and:[str peek == $)]]
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
        ] whileFalse.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   379
        millis := (seconds*1000) + millis.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   380
        restMillis := millis - millis truncated.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   381
        millis := millis truncated.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   382
        picos := picos + (restMillis * 1000 * 1000 * 1000) truncated. 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   383
        millis := millis + (picos // (1000*1000*1000)).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   384
        picos := picos \\ (1000*1000*1000).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   385
        t := self fromMilliseconds:millis asInteger.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   386
        t additionalPicoseconds:picos.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   387
        t
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   388
    ] on:Error do:[:ex |
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
        |t|
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
        "/ retry, using inherited readFrom (Object-storeString)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
        t := Object readFrom:aStringOrStream onError:[^ exceptionBlock value].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
        (t isKindOf:TimeDuration) ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
            ^ exceptionBlock value
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
        t
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
    "
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   400
     TimeDuration readFrom:'2' defaultUnit:$h onError:nil -> 2h
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   401
     TimeDuration readFrom:'100' defaultUnit:$m onError:nil -> 1h 40m
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   402
     TimeDuration readFrom:'100' defaultUnit:$s onError:nil -> 1m 40s
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   403
     TimeDuration readFrom:'0200' defaultUnit:$h onError:nil -> 1w 1d 8h
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
     TimeDuration readFrom:'1h'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
     TimeDuration readFrom:'1h 35m'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
     TimeDuration readFrom:'25h'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
     TimeDuration readFrom:'3d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
     TimeDuration readFrom:'1w'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
     TimeDuration readFrom:'120s'     
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   411
     TimeDuration readFrom:'1500ms'    
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
     TimeDuration readFrom:'3ms'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
     TimeDuration readFrom:'1yr 5d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
     TimeDuration readFrom:'1mon'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
     TimeDuration readFrom:'05:10'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
     TimeDuration readFrom:'05:10:5'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
     TimeDuration readFrom:'05:10:5.150'  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   419
     TimeDuration readFrom:'-1h'
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   420
     TimeDuration readFrom:'-1h 10m'
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   421
     TimeDuration readFrom:'1h -10m'
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   422
     TimeDuration readFrom:'-(1h 10m)' 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   423
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   424
     TimeDuration readFrom:'1ms' -> 1ms 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   425
     TimeDuration readFrom:'5us' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   426
     TimeDuration readFrom:'5µs' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   427
     TimeDuration readFrom:'5ns' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   428
     TimeDuration readFrom:'5ps' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   429
     TimeDuration readFrom:'5005 ps' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   430
     TimeDuration readFrom:'1.01 s' -> 1.010s 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   431
     TimeDuration readFrom:'1.001 s' -> 1.001s 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   432
     TimeDuration readFrom:'1.0001 s' -> 1.0001s 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   433
     TimeDuration readFrom:'1s 5ns' -> 1.000000005s
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   434
     (TimeDuration readFrom:'1s 5ns') = (TimeDuration fromNanoseconds:(5+1000000000))
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   435
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
     TimeDuration readFrom:(TimeDuration new storeString)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
    "Modified: / 08-10-2007 / 16:41:48 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
readFrom:aStringOrStream onError:exceptionBlock
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
    "return a new TimeDuration, reading a printed representation from aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
     The format is [n 'yr'] [n 'mon'] [n 'w'] [n 'd'] [n 'h'] [n 'm'] [n 's'] [n 'ms']
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
     where 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
            yr -> year
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
            mon -> month
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
            w -> week
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
            d -> day
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
            h -> hour
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
            m -> minutes
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
            s -> seconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
            ms -> milliseconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
     The yr and mon specifiers stand for 365d and 30d respectively.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
     If no unit is given (i.e. a plain number string is given), assume seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
    ^ self readFrom:aStringOrStream defaultUnit:$s onError:exceptionBlock
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
     TimeDuration readFrom:'100' onError:nil      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
     TimeDuration readFrom:'100' defaultUnit:$m onError:nil 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
     TimeDuration readFrom:'1h'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
     TimeDuration readFrom:'1h 35m'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
     TimeDuration readFrom:'25h'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
     TimeDuration readFrom:'3d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
     TimeDuration readFrom:'1w'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
     TimeDuration readFrom:'120s'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
     TimeDuration readFrom:'1500ms    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
     TimeDuration readFrom:'3ms'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
     TimeDuration readFrom:'1yr 5d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
     TimeDuration readFrom:'1mon'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
    "Modified: / 08-10-2007 / 16:41:48 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
seconds:s
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
    "return a new TimeDuration representing a duration of s seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
    s == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   485
    ^ self basicNew setMilliseconds:(s * 1000)
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
     TimeDuration seconds:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
    "Created: / 06-08-2007 / 15:32:21 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
weeks:w 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
    "return a new TimeDuration representing a duration of w weeks."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
    ^ self days:(w * 7)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
     TimeDuration weeks:1  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
    "Created: / 05-09-2011 / 11:18:27 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
!TimeDuration class methodsFor:'class initialization'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
initialize
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
    TimeDurationZero isNil ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
        TimeDurationZero := self basicNew setHours:0 minutes:0 seconds:0 milliseconds:0.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
    "Modified: / 10-05-2011 / 10:31:35 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
!TimeDuration class methodsFor:'constants'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
zero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
    "return the neutral element for addition (0s)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
    ^ TimeDurationZero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
    "Modified: 18.7.1996 / 12:26:12 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
!TimeDuration class methodsFor:'format strings'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
defaultFormatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    ^  DefaultFormatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
defaultFormatForPrinting:aString
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
    DefaultFormatForPrinting := aString
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
formatString12us
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
    "return the format string used to format US times (and other areas)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   539
    ^ '%h:%m:%s.%i'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   540
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   541
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   542
formatString24
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   543
    "return the format string used to format european times (and other areas)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   544
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   545
    ^ '%h:%m:%s.%i'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   546
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   547
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   548
!TimeDuration class methodsFor:'timing evaluation'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
toRun:aBlock
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
    "return the TimeDuration it takes to execute aBlock.                          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
     A modern variant of Time millisecondsToRun: (which prints itself nicely)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   554
    ^ self microseconds:(Time microsecondsToRun:aBlock).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
     TimeDuration toRun:[ 20000 factorial ]     
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   558
     TimeDuration toRun:[ 2000 factorial ]     
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   559
     TimeDuration toRun:[ 900 factorial ]     
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
!TimeDuration methodsFor:'accessing'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   565
asExactMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   566
    "return the exact number of mcroseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   567
     In contrast to getMicroSeconds, which returns them truncated."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   568
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   569
    additionalPicoseconds isNil ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   570
        ^ (timeEncoding * 1000) "/ millis as micros
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   571
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   572
    ^ (timeEncoding * 1000)                    "/ millis as micros 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   573
    + (additionalPicoseconds / (1000 * 1000))  "/ picos as microseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   574
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   575
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   576
     40 milliseconds asExactMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   577
     40 microseconds asExactMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   578
     40 nanoseconds asExactMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   579
     40 picoseconds asExactMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   580
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   581
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   582
    "Created: / 21-09-2017 / 18:52:26 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   583
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   584
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   585
asExactMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   586
    "return the exact number of milliseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   587
     In contrast to getMilliSeconds, which returns them truncated."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   588
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   589
    additionalPicoseconds isNil ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   590
        ^ (timeEncoding) "/ millis
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   591
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   592
    ^ (timeEncoding)                         "/ millis 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   593
    + (additionalPicoseconds / (1000 * 1000 * 1000))  "/ picos as milliseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   594
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   595
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   596
     40 milliseconds asExactMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   597
     40 microseconds asExactMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   598
     40 nanoseconds asExactMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   599
     40 picoseconds asExactMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   600
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   601
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   602
    "Created: / 21-09-2017 / 18:52:26 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   603
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   604
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   605
asExactNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   606
    "return the exact number of nanoseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   607
     In contrast to getnanoSeconds, which returns them truncated."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   608
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   609
    additionalPicoseconds isNil ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   610
        ^ (timeEncoding * 1000 * 1000) "/ millis as nanos
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   611
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   612
    ^ (timeEncoding * 1000 * 1000)          "/ millis as nanos 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   613
    + (additionalPicoseconds / (1000))      "/ picos as nanoseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   614
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   615
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   616
     40 milliseconds asExactNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   617
     40 microseconds asExactNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   618
     40 nanoseconds asExactNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   619
     40 picoseconds asExactNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   620
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   621
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   622
    "Created: / 21-09-2017 / 18:52:26 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   623
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   624
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   625
asExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   626
    "return the exact number of seconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   627
     In contrast to getSeconds, which returns them truncated."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   628
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   629
    additionalPicoseconds isNil ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   630
        ^ (timeEncoding / 1000) "/ millis as seconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   631
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   632
    ^ (timeEncoding / 1000)                         "/ millis as seconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   633
    + additionalPicoseconds / (1000 * 1000 * 1000 * 1000)  "/ picos as seconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   634
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   635
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   636
     40 milliseconds getExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   637
     40 microseconds getExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   638
     40 nanoseconds getExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   639
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   640
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   641
    "Created: / 21-09-2017 / 18:52:26 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   642
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   643
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   644
days
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   645
    "get the (truncated) total number of days.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   646
     Use this only for printing.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   647
     Sigh: this is inconsistent: hours, minutes, seconds etc. 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   648
     return the fraction, not the total"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   649
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   650
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   651
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   652
            t // 1000 // 3600 // 24
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   653
        ].    
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   654
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   655
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   656
     (Duration fromString:'1mon 1d 4h 3m 5s 10ms') days
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   657
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   658
     (Duration days:9 hours:1 minutes:2 seconds:3) days   
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   659
     (Duration days:-9 hours:-1 minutes:-2 seconds:-3) days 
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   660
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   663
hours
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   664
    "get the (truncated) number of hours.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   665
     notice: that is NOT the total number of hours,
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   666
     but the fractional part only. 
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   667
     Use this only for printing"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   668
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   669
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   670
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   671
            (t // 1000 // 3600 \\ 24)
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   672
        ]
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   673
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   674
     (Duration fromString:'1d 4h 3m 5s 10ms') hours
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   675
     (Duration fromString:'1d 4h 3m 1s 10ms') getHours
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   676
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   677
     (Duration days: 9 hours: 1 minutes: 2 seconds: 3) hours
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   678
     (Duration days: -9 hours: -1 minutes: -2 seconds: -3) hours
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   679
    "
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   680
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   681
    "Modified (comment): / 21-09-2017 / 18:53:32 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   682
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   683
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   684
milliseconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
    "get the milliseconds part 
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   686
     notice: that is NOT the total number of millis,
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   687
     but the fractional part (within the second) only. 
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   688
     Use this only for printing.
19849
e989f43ce274 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19023
diff changeset
   689
     asMilliseconds or getMilliseconds is probably what you want"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   690
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   691
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   692
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   693
            t \\ 1000
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   694
        ].    
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   695
    "
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   696
     (Duration milliseconds:10) milliseconds
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   697
     (Duration milliseconds:-10) milliseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   698
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   699
     (Duration fromString:'1s 10ms') milliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   700
     (Duration fromString:'1s 10ms') getMilliseconds
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   701
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   702
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   703
    "Modified: / 05-05-2010 / 14:22:04 / cg"
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   704
    "Modified (comment): / 21-09-2017 / 18:53:26 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   706
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   707
minutes
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   708
    "get the number of minutes.
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   709
     notice: that is NOT the total number of minutes,
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   710
     but the fractional part only. 
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   711
     Use this only for printing"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   712
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   713
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   714
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   715
            t // 1000 // 60 \\ 60
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   716
        ]
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   717
        
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   718
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   719
     (Duration fromString:'1h 3m 5s 10ms') minutes
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   720
     (Duration fromString:'1h 3m 1s 10ms') getMinutes
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   721
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   722
     (Duration days: 9 hours: 1 minutes: 2 seconds: 3) minutes
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   723
     (Duration days: -9 hours: -1 minutes: -2 seconds: -3) minutes
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   724
    "
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   725
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   726
    "Modified (comment): / 21-09-2017 / 18:53:22 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   727
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   728
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   729
picoseconds
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   730
    "get the optional additional picoseconds (0..999999999)
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   731
     notice: that is NOT the total number of picoseconds,
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   732
     but the fractional part (within the second) only. 
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   733
     Use this only for printing."
22620
c77e738e5d23 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22519
diff changeset
   734
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   735
    ^ (self milliseconds * 1000 * 1000 * 1000) + (additionalPicoseconds ? 0)
22620
c77e738e5d23 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22519
diff changeset
   736
!
c77e738e5d23 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22519
diff changeset
   737
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
seconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
    "get the number of seconds.
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   740
     notice: that is NOT the total number of seconds,
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   741
     but the fractional part only. 
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   742
     Use this only for printing.
19849
e989f43ce274 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19023
diff changeset
   743
     asSeconds or getSeconds is probably what you want"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   744
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   745
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   746
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   747
            t // 1000 \\ 60
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   748
        ]
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   749
        
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   750
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   751
     (Duration fromString:'1m 5s 10ms') seconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   752
     (Duration fromString:'1m 1s 10ms') getSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   753
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   754
     (Duration days: 9 hours: 1 minutes: 2 seconds: 3) seconds
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   755
     (Duration days: -9 hours: -1 minutes: -2 seconds: -3) seconds
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   756
    "
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   757
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   758
    "Modified (comment): / 21-09-2017 / 18:53:13 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   759
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   760
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   761
!TimeDuration methodsFor:'arithmetic'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   762
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   763
* aNumber
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   764
    "return a new scaled timeDuration"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   765
19022
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   766
    aNumber isNumber ifTrue:[
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   767
        ^ self species basicNew 
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   768
            setMilliseconds:(self getMilliseconds * aNumber) asInteger
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   769
    ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   770
    "/ notice: although noone seems to implement it (currently),
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   771
    "/ there are additional packages which add support (i.e. goodies/physic),
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   772
    "/ so do not remove the call below.
19022
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   773
    ^ aNumber productFromTimeDuration:self
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   774
    
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   775
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   776
     5 c* (TimeDuration fromString:'10s')
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   777
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   778
     (TimeDuration fromString:'10s') * 5
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   779
     (TimeDuration fromString:'10s') * 10
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   780
     (TimeDuration fromString:'10s') * 100
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   781
     (TimeDuration fromString:'10s') * 1000
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   782
     (TimeDuration fromString:'-10s') * 1000
22621
ea38224ef388 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22620
diff changeset
   783
     (TimeDuration fromString:'10s') * (TimeDuration fromString:'10s')
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   784
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   785
     (TimeDuration fromString:'10ms') * 5
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   786
     (TimeDuration fromString:'10us') * 5
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   787
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   788
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   789
22633
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   790
+ aTimeDurationOrNumberOfSeconds
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   791
    "return a new timeDuration"
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   792
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   793
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   794
        ^ self species basicNew 
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   795
            setMilliseconds:(self getMilliseconds + (aTimeDurationOrNumberOfSeconds * 1000) asInteger)
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   796
    ].
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   797
    ^ self species basicNew
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   798
        setMilliseconds:(self getMilliseconds + aTimeDurationOrNumberOfSeconds getMilliseconds)
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   799
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   800
    "
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   801
     (TimeDuration fromString:'1m') + (TimeDuration fromString:'10s') 
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   802
     1 minutes + 10 seconds
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   803
    "
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   804
!
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
   805
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   806
/ aTimeDurationOrNumberOfSeconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   807
    "if the argument is a number, return a new timeDuration.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   808
     Otherwise, return the quotient as a number."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   809
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   810
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   811
        ^ self species basicNew 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   812
            setMilliseconds:(self getMilliseconds / aTimeDurationOrNumberOfSeconds) asInteger
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   813
    ].
19023
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   814
    aTimeDurationOrNumberOfSeconds isTimeDuration ifTrue:[
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   815
        ^ (self getMilliseconds / aTimeDurationOrNumberOfSeconds getMilliseconds)
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   816
    ].
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   817
    ^ aTimeDurationOrNumberOfSeconds quotientFromTimeDuration:self
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   818
    
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
     (TimeDuration fromString:'10s') / (TimeDuration fromString:'5s')
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
     (TimeDuration fromString:'10s') / 5
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   824
16403
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   825
abs
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   826
    timeEncoding >= 0 ifTrue:[
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   827
        ^ self. 
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   828
    ].
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   829
    ^ self class new timeEncoding:(timeEncoding negated)
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   830
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   831
    "
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   832
        (TimeDuration fromSeconds:20000) abs
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   833
        (TimeDuration fromSeconds:-20000) abs
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   834
    "
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   835
!
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   836
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
negated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
    ^ self class new timeEncoding:(timeEncoding negated)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   840
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   841
productFromFloat:aFloat
21800
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   842
    "sent when aFloat does not know how to multiply the receiver.
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   843
     Return a new timeDuration"
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   844
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   845
    ^ self productFromNumber:aFloat
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   846
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   847
    "
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   848
     5.1 * (TimeDuration fromString:'10s') 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   849
    "
21800
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   850
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   851
    "Modified (comment): / 12-06-2017 / 20:51:38 / cg"
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   852
!
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   853
21800
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   854
productFromFraction:aFraction
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   855
    "sent when aFraction does not know how to multiply the receiver.
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   856
     Return a new timeDuration"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   857
21800
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   858
    ^ self productFromNumber:aFraction
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   859
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   860
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   861
     (TimeDuration fromString:'10s') * 5
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   862
    "
21800
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   863
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   864
    "Modified (comment): / 12-06-2017 / 20:51:25 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   865
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   866
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   867
productFromInteger:anInteger
21800
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   868
    "sent when an integer does not know how to multiply the receiver"
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   869
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   870
    ^ self productFromNumber:anInteger
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   871
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   872
    "
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   873
     5 * (TimeDuration fromString:'10s') 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   874
    "
21800
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   875
4f0593d4b67c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21757
diff changeset
   876
    "Modified (comment): / 12-06-2017 / 20:50:56 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   877
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   878
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   879
!TimeDuration methodsFor:'converting'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   880
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   881
asFixedPoint
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   882
    "answer the duration as seconds.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   883
     Better use the explicit getSeconds"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   884
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   885
    ^ FixedPoint numerator:timeEncoding denominator:1000 scale:4 
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   886
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   887
    "
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   888
     (10 milliseconds) asFixedPoint
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   889
     (10 milliseconds) asFixedPoint asFixedPoint:3 
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   890
    "
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   891
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   892
    "Modified (comment): / 14-09-2017 / 15:15:24 / stefan"
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   893
!
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   894
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   895
asFixedPoint:scale
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   896
    "answer the duration as seconds.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   897
     Better use the explicit getSeconds"
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   898
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   899
    ^ FixedPoint numerator:timeEncoding denominator:1000 scale:scale 
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   900
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   901
    "
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   902
     (10 milliseconds) asFixedPoint  
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   903
     (10 milliseconds) asFixedPoint:3 
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   904
    "
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
   905
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
   906
    "Modified (comment): / 14-09-2017 / 15:15:24 / stefan"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   907
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   908
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   909
asFloat
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   910
    "answer the duration as seconds.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   911
     Better use the explicit getSeconds"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   912
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   913
    ^ timeEncoding / 1000.0
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   914
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   915
    "
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   916
     (10 milliseconds) asFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   917
    "
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
   918
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
   919
    "Modified (comment): / 14-09-2017 / 15:15:18 / stefan"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   920
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   921
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   922
asFraction
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   923
    "answer the duration as seconds.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   924
     Better use the explicit getSeconds"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   925
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   926
    ^ timeEncoding / 1000
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   927
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   928
    "
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   929
     (10 milliseconds) asFraction
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   930
     (1 seconds) asFraction
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   931
    "
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
   932
22493
0232ebe18eb8 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22286
diff changeset
   933
    "Modified (comment): / 19-01-2018 / 17:29:24 / stefan"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   934
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   935
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   936
asInteger
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   937
    "answer the duration as (truncated) seconds.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   938
     Better use the explicit getSeconds"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   939
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   940
    ^ self getSeconds
21506
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
   941
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
   942
    "
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   943
     10 milliseconds asInteger
21506
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
   944
    "
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
   945
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
   946
    "Modified (comment): / 14-09-2017 / 15:14:49 / stefan"
22285
196d6c806fae #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22284
diff changeset
   947
    "Modified (comment): / 21-09-2017 / 18:57:43 / cg"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   948
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   949
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   950
asLongFloat
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   951
    "answer the duration as longfloat seconds.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   952
     Better use the explicit getSeconds"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   953
16479
9c0562f22996 Fix LongFloat botch
Stefan Vogel <sv@exept.de>
parents: 16478
diff changeset
   954
    ^ timeEncoding / 1000 asLongFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   955
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   956
    "
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   957
     (10 milliseconds)  asLongFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   958
    "
21895
cd9916b88990 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21800
diff changeset
   959
cd9916b88990 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 21800
diff changeset
   960
    "Modified (comment): / 21-06-2017 / 13:59:54 / cg"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   961
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   962
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   963
asMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   964
    "answer the duration as microseconds (truncated)."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   965
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   966
    ^ self getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   967
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   968
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   969
     10 milliseconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   970
     10 seconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   971
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   972
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   973
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   974
asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   975
    "answer the duration as milliseconds (truncated)."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   976
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   977
    ^ self getMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   978
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   979
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   980
     10 milliseconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   981
     10 seconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   982
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   983
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   984
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   985
asNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   986
    "answer the duration as nanoseconds (truncated)."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   987
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   988
    ^ self getNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   989
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   990
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   991
     10 milliseconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   992
     10 seconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   993
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   994
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   995
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   996
asNumber
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   997
    "answer the duration as seconds"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
   998
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   999
    ^ self asExactSeconds
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1000
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1001
    "Modified (comment): / 14-09-2017 / 15:15:00 / stefan"
22285
196d6c806fae #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22284
diff changeset
  1002
    "Modified: / 21-09-2017 / 18:57:57 / cg"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1003
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1004
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1005
asSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1006
    "answer the duration as seconds (truncated, for now).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1007
     To get the exact number, use asExactSeconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1008
     Please change senders to use asTruncatedSeconds to make this truncation explicit;
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1009
     for now, this returns the truncated value for backward compatibility"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1010
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1011
    ^ self asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1012
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1013
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1014
     10 milliseconds asSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1015
     10 nanoseconds asSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1016
     10 milliseconds asExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1017
     10 nanoseconds asExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1018
     2 minutes asSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1019
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1020
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1021
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1022
asTimeDuration
20430
8ebafa5313a1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19930
diff changeset
  1023
    "return a TimeDuration object from the receiver - that's the receiver."
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1024
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1025
    ^ self
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1026
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1027
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1028
asTruncatedMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1029
    "answer the duration as microseconds (truncated)."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1030
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1031
    ^ self getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1032
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1033
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1034
     10 milliseconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1035
     10 seconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1036
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1037
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1038
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1039
asTruncatedMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1040
    "answer the duration as milliseconds (truncated)."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1041
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1042
    ^ self getMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1043
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1044
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1045
     10 milliseconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1046
     10 seconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1047
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1048
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1049
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1050
asTruncatedNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1051
    "answer the duration as nanoseconds (truncated)."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1052
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1053
    ^ self getNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1054
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1055
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1056
     10 milliseconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1057
     10 seconds getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1058
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1059
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1060
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1061
asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1062
    "answer the duration as seconds (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1063
     To get the exact number, use asExactSeconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1064
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1065
    ^ self getSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1066
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1067
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1068
     10 milliseconds asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1069
     10 milliseconds asExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1070
     2 minutes asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1071
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1072
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1073
22633
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1074
!TimeDuration methodsFor:'double dispatching'!
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1075
22633
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1076
differenceFromTimestamp:aTimestamp
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1077
    "return the timestamp this timeDuration before aTimestamp"
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1078
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1079
    ^ aTimestamp subtractMilliseconds:(self getMilliseconds)
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1080
!
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1081
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1082
productFromNumber:aNumber
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1083
    "sent when an integer does not know how to multiply the receiver.
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1084
     Return a new timeDuration"
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1085
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1086
    ^ self species basicNew 
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1087
        setMilliseconds:(self getMilliseconds * aNumber) asInteger
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1088
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1089
    "
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1090
     5.1 * (TimeDuration fromString:'10s') 
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1091
    "
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1092
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1093
    "Modified (comment): / 12-06-2017 / 20:50:51 / cg"
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1094
!
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1095
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1096
sumFromTimestamp:aTimestamp
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1097
    "return the timestamp this timeDuration after aTimestamp"
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1098
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1099
    ^ aTimestamp addMilliseconds:(self getMilliseconds)
168193740976 #BUGFIX by mawalch
mawalch
parents: 22625
diff changeset
  1100
! !
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1101
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1102
!TimeDuration methodsFor:'printing'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1103
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1104
addPrintBindingsTo:aDictionary language:languageOrNil
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1105
    "private print support: add bindings for printing to aDictionary.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1106
     languageOrNil can only be #en or nil for the current language.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1107
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1108
     Additional formats available here (for timeDuration) are:
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1109
        %(Hd)       hours in day (i.e. 0..23)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1110
        %(hd)       hours in day padded to 2 chars (i.e. 00..23)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1111
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1112
        %(yrR)      years rounded (i.e. for 730 days, we get 2 asFixedPoint:1 )
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1113
        %(monR)     month rounded (i.e. for 45 days, we get 1.5 asFixedPoint:1 )
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1114
        %(w)        weeks 
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1115
        %(wR)       weeks rounded (i.e. for 45 days, we get 6.xxx asFixedPoint:1 )
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1116
        %(dR)       days rounded (i.e. for 36 hours, we get 1.5 asFixedPoint:1 )
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1117
        %(dw)       days in week (rest days after taking out the weeks)
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1118
        %(hR)       hours rounded (i.e. for 3h 30m, we get 3.5 asFixedPoint:1 )
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1119
        %(mR)       minutes rounded (i.e. for 2m 30s, we get 2.5 asFixedPoint:1 )
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1120
        %(sR)       seconds rounded to 1 postDecimal (i.e. for 2s 100ms, we get 2.1 asFixedPoint:1 )
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1121
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1122
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1123
    |hoursInDay s yearsRounded monthsRounded weeksRounded daysRounded hoursRounded minutesRounded secondsRounded|
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1124
16830
1d5965daab9a class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16506
diff changeset
  1125
    self addBasicPrintBindingsTo:aDictionary language:languageOrNil.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1126
    aDictionary at:$d put:self days.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1127
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1128
    hoursInDay := self hours \\ 24.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1129
    aDictionary at:#Hd put:(s := hoursInDay printString).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1130
    aDictionary at:#hd put:(s leftPaddedTo:2 with:$0).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1131
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1132
    aDictionary at:#dw put:(self days \\ 7).
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1133
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1134
    yearsRounded := (self hours / 24 / 365).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1135
    yearsRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1136
        yearsRounded := yearsRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1137
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1138
    aDictionary at:#yrR put:yearsRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1139
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1140
    monthsRounded := self days / 30.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1141
    monthsRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1142
        monthsRounded := monthsRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1143
        monthsRounded roundedToScale = monthsRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1144
            monthsRounded := monthsRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1145
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1146
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1147
    aDictionary at:#monR put:monthsRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1148
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1149
    aDictionary at:#w put:(self days // 7).
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1150
    weeksRounded := self days / 7.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1151
    weeksRounded isInteger ifFalse:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1152
        weeksRounded := weeksRounded asFixedPoint:1.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1153
        weeksRounded roundedToScale = weeksRounded asInteger ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1154
            weeksRounded := weeksRounded truncated
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1155
        ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1156
    ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1157
    aDictionary at:#wR put:weeksRounded.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1158
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1159
    daysRounded := (self hours / 24).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1160
    daysRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1161
        daysRounded := daysRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1162
        daysRounded roundedToScale = daysRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1163
            daysRounded := daysRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1164
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1165
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1166
    aDictionary at:#dR put:daysRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1167
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1168
    hoursRounded := self hours + (self minutes / 60).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1169
    hoursRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1170
        hoursRounded := hoursRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1171
        hoursRounded roundedToScale = hoursRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1172
            hoursRounded := hoursRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1173
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1174
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1175
    aDictionary at:#hR put:hoursRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1176
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1177
    minutesRounded := self minutes + (self seconds / 60).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1178
    minutesRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1179
        minutesRounded := minutesRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1180
        minutesRounded roundedToScale = minutesRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1181
            minutesRounded := minutesRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1182
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1183
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1184
    aDictionary at:#mR put:minutesRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1185
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1186
    secondsRounded := self seconds + (self milliseconds / 1000).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1187
    secondsRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1188
        secondsRounded := secondsRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1189
        secondsRounded roundedToScale = secondsRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1190
            secondsRounded := secondsRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1191
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1192
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1193
    aDictionary at:#sR put:secondsRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1194
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1195
    "Modified: / 22-02-2011 / 15:55:38 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1196
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1197
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1198
formatForApproximatePrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1199
    "Return a format which is suitable for a human - not meant to be read back.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1200
     In contrast to the regular format, this one only gives a rounded approximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1201
     of the time duration as useful in information-dialogs or other user-hint-GUI elements.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1202
     For example, in a timeDuration of more than 2hours, the user might not be interested in
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1203
     individual seconds or even milliseconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1204
     The way this hidding/rounding is done is pure magic heuristics."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1205
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1206
    |hours mins secs ms|
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1207
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1208
    hours := self hours.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1209
22286
b67c6cd14b84 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22285
diff changeset
  1210
    hours >= (24*365*2) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1211
        ^ '%(yrR)yr'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1212
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1213
    hours >= (24*40) ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1214
        ^ '%(monR)mon'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1215
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1216
    hours >= 48 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1217
        ^ '%(dR)d'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1218
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1219
    hours >= 24 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1220
        ^ '%dd %(Hd)h'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1221
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1222
    hours >= 2 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1223
        ^ '%(hR)h'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1224
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1225
    hours >= 1 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1226
        ^ '%Hh %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1227
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1228
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1229
    "/ no hours
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1230
    mins := self minutes.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1231
    mins >= 5 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1232
        ^ '%(mR)m'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1233
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1234
    mins >= 1 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1235
        ^ '%Mm %Ss'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1236
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1237
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1238
    "/ no mins
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1239
    secs := self seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1240
    secs >= 1 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1241
        secs >= 30 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1242
            ^ '%(S)s'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1243
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1244
        ^ '%(sR)s'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1245
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1246
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1247
    "/ no secs
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1248
    ms := self milliseconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1249
    ms > 500 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1250
        ^ '%(sR)s'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1251
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1252
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1253
    ^ self formatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1254
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1255
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1256
     (TimeDuration hours:0 minutes:0 seconds:0 millis:12) printStringForApproximation       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1257
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1258
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1259
     (TimeDuration hours:0 minutes:1 seconds:10 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1260
     (TimeDuration hours:0 minutes:2 seconds:10 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1261
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1262
     (TimeDuration hours:2 minutes:0 seconds:0 millis:123) printStringForApproximation         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1263
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1264
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringForApproximation      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1265
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringForApproximation    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1266
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringForApproximation    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1267
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1268
     (TimeDuration hours:2 minutes:33 seconds:0 millis:0) printStringForApproximation         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1269
     (TimeDuration hours:2 minutes:0 seconds:0 millis:0) printStringForApproximation          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1270
     (TimeDuration hours:24 minutes:0 seconds:0 millis:0) printStringForApproximation          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1271
    "
22286
b67c6cd14b84 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22285
diff changeset
  1272
b67c6cd14b84 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22285
diff changeset
  1273
    "Modified: / 21-09-2017 / 22:19:53 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1274
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1275
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1276
formatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1277
    "Return the format for printing"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1278
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1279
    DefaultFormatForPrinting notNil ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1280
        ^ DefaultFormatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1281
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1282
    ^ self formatForPrinting:false
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1283
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1284
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1285
     (TimeDuration readFrom:'10h 3s') formatForPrinting  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1286
     (TimeDuration readFrom:'3s') formatForPrinting      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1287
     (TimeDuration readFrom:'1d 2ms') formatForPrinting      
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1288
     (TimeDuration readFrom:'1 week') formatForPrinting      
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1289
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1290
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1291
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1292
formatForShortPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1293
    "Return the short format for printing (without ms)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1294
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1295
    ^ self formatForPrinting:true
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1296
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1297
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1298
printAsApproximationOn:aStream
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1299
    "append a human readable printed representation of the receiver to aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1300
     The format is meant for a human and does not give all information;
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1301
     especially, useless detail is hidden.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1302
     This means, that seconds are rounded or hidden, if the dT is more than a few minutes;
21446
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  1303
     minutes rounded into the hour or hidden, if it's more than a few hours etc.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1304
     The way this is done is pure magic heuristics - let me know, if you have a better algorithm."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1305
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1306
    ^ self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1307
        printOn:aStream 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1308
        format:(self formatForApproximatePrinting).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1309
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1310
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1311
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1312
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1313
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1314
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1315
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1316
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1317
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1318
     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1319
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1320
     (TimeDuration hours:2 minutes:33 seconds:0) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1321
     (TimeDuration hours:2 minutes:0 seconds:0) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1322
     (TimeDuration hours:24 minutes:0 seconds:0) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1323
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1324
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1325
    "Modified: / 18-07-2007 / 14:06:17 / cg"
21446
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  1326
    "Modified (comment): / 13-02-2017 / 20:32:54 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1327
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1328
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1329
printOn:aStream
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1330
    "append a human readable printed representation of the receiver to aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1331
     The format is suitable for a human - not meant to be read back."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1332
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1333
    timeEncoding negative ifTrue:[
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1334
        aStream nextPutAll:'-('.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1335
        (self class basicNew timeEncoding:timeEncoding negated) printOn:aStream.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1336
        aStream nextPutAll:')'.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1337
        ^  self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1338
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1339
    ^ self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1340
        printOn:aStream 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1341
        format:(self formatForPrinting).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1342
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1343
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1344
     TimeDuration hours:0 minutes:0 seconds:0 millis:12       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1345
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1346
     TimeDuration hours:0 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1347
     TimeDuration hours:0 minutes:0 seconds:10 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1348
     TimeDuration hours:0 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1349
     TimeDuration hours:2 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1350
     TimeDuration hours:2 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1351
     TimeDuration hours:100 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1352
     TimeDuration hours:10000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1353
     TimeDuration hours:1000000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1354
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1355
     TimeDuration hours:2 minutes:33 seconds:0 millis:0         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1356
     TimeDuration hours:2 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1357
     TimeDuration hours:24 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1358
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1359
     (TimeDuration hours:0 minutes:0 seconds:0 millis:123) printStringFormat:'%h:%m:%s'       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1360
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1361
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1362
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1363
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1364
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1365
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1366
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1367
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1368
    "Modified: / 18-07-2007 / 14:06:17 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1369
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1370
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1371
printShortOn:aStream
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1372
    "append a human readable printed representation  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1373
     of the receiver to aStream (without milliseconds)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1374
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1375
    ^ self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1376
        printOn:aStream 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1377
        format:(self formatForShortPrinting).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1378
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1379
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1380
     TimeDuration hours:0 minutes:0 seconds:0 millis:12       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1381
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1382
     TimeDuration hours:0 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1383
     TimeDuration hours:0 minutes:0 seconds:10 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1384
     TimeDuration hours:0 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1385
     TimeDuration hours:2 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1386
     TimeDuration hours:2 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1387
     TimeDuration hours:100 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1388
     TimeDuration hours:10000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1389
     TimeDuration hours:1000000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1390
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1391
     TimeDuration hours:2 minutes:33 seconds:0 millis:0         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1392
     TimeDuration hours:2 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1393
     TimeDuration hours:24 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1394
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1395
     (TimeDuration hours:0 minutes:0 seconds:0 millis:123) printStringFormat:'%h:%m:%s'       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1396
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1397
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1398
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1399
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1400
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1401
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1402
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1403
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1404
    "Modified: / 18-07-2007 / 14:06:17 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1405
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1406
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1407
printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1408
    "return a human readable printed representation of the receiver to aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1409
     The format is meant for a human and does not give all information;
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1410
     especially, useless detail is hidden.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1411
     This means, that seconds are rounded or hidden, if the dT is more than a few minutes;
21446
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  1412
     minutes rounded into the hour or hidden, if it's more than a few hours etc.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1413
     The way this is done is pure magic heuristics - let me know, if you have a better algorithm."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1414
20837
3e0095bef7e6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20704
diff changeset
  1415
    ^ self printStringFormat:(self formatForApproximatePrinting).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1416
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1417
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1418
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1419
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1420
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1421
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1422
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1423
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1424
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1425
     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1426
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1427
     (TimeDuration hours:2 minutes:33 seconds:0) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1428
     (TimeDuration hours:2 minutes:0 seconds:0) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1429
     (TimeDuration hours:24 minutes:0 seconds:0) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1430
    "
21446
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  1431
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  1432
    "Modified (comment): / 13-02-2017 / 20:32:59 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1433
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1434
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1435
!TimeDuration methodsFor:'private'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1436
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1437
additionalPicoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1438
    "get the optional additional picoseconds (0..999999999)
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1439
     notice: that is NOT the total number of picoseconds,
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1440
     but the fractional part only. 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1441
     Use this only for printing."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1442
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1443
    ^ additionalPicoseconds ? 0
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1444
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1445
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1446
additionalPicoseconds:picosecondPart
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1447
    "set the optional additional picoseconds (0..999999999)"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1448
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1449
    self assert:(picosecondPart isInteger).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1450
    self assert:(picosecondPart < (1000*1000*1000)).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1451
    additionalPicoseconds := picosecondPart
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1452
!
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1453
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1454
formatForPrinting:shortFlag
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1455
    "Return a format which is suitable for a human (i.e. not ISO8601) 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1456
     (not meant to be read back because it will not print tiny fractions,
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1457
      but instead round it heuristically.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1458
     However, the reader can read that format, but you'll loose some precision if you do).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1459
     If shortFlag is true, some millisecond-info is omitted for longer times.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1460
     For timeDurations to be read back exactly, use iso8601 format."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1461
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1462
    |fmt days weeks hours mins secs 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1463
     overAllSeconds overAllMicros overAllNanos millis|
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1464
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1465
    days := self days.  "/ that's the total
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1466
    weeks := days // 7.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1467
    hours := self hours.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1468
    mins := self minutes.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1469
    secs := self seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1470
    millis := self milliseconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1471
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1472
    "/ q: for up to 2 weeks, whould we better generate: "10d" instead of "1w 3d" ??
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1473
    weeks > 0 ifTrue:[
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1474
        "/ notice: dw here, which prints the remaining days, after taking out the weeks
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1475
        fmt := '%(w)w %(dw)d %(Hd)h %Mm'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1476
        secs = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1477
            fmt := '%(w)w %(dw)d %(Hd)h %Mm'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1478
            mins = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1479
                fmt := '%(w)w %(dw)d %(Hd)h'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1480
                (hours \\ 24) = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1481
                    fmt := '%(w)w %(dw)d'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1482
                    (days \\ 7) = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1483
                        fmt := '%(w)w'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1484
                    ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1485
                ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1486
            ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1487
        ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1488
    ] ifFalse:[days > 0 ifTrue:[
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1489
        "/ notice: d here, which prints the total number of days
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1490
        fmt := '%dd %(Hd)h %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1491
        secs = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1492
            fmt := '%dd %(Hd)h %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1493
            mins = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1494
                fmt := '%dd %(Hd)h'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1495
                (hours \\ 24) = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1496
                    fmt := '%dd'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1497
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1498
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1499
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1500
    ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1501
        hours > 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1502
            fmt := '%Hh %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1503
            secs = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1504
                fmt := '%Hh %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1505
                mins = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1506
                    fmt := '%Hh'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1507
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1508
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1509
        ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1510
            mins > 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1511
                fmt := '%Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1512
                secs = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1513
                    fmt := '%Mm'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1514
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1515
            ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1516
                fmt := ''
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1517
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1518
        ].
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1519
    ]].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1520
    ((secs ~= 0) or:[millis ~= 0 or:[(additionalPicoseconds?0) ~= 0]]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1521
        fmt size ~~ 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1522
            fmt := fmt , ' '
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1523
        ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1524
        ((millis = 0) and:[(additionalPicoseconds?0) = 0]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1525
            fmt := fmt , '%Ss'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1526
        ] ifFalse:[
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1527
            (secs = 0 and:[(additionalPicoseconds?0) = 0]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1528
                fmt := fmt , '%Ims'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1529
            ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1530
                shortFlag ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1531
                    "/ show millis
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1532
                    (millis ~= 0) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1533
                        fmt := fmt , '%S.%is'
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1534
                    ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1535
                        overAllMicros := self asMicroseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1536
                        overAllMicros > 2 ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1537
                            fmt := fmt , '%(micro)us'.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1538
                        ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1539
                            overAllNanos := self asNanoseconds.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1540
                            overAllNanos > 2 ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1541
                                fmt := fmt , '%(nano)ns'.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1542
                            ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1543
                                fmt := fmt , '%(pico)ps'.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1544
                            ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1545
                        ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1546
                    ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1547
                ] ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1548
                    "/ only show millis if the number of seconds is small
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1549
                    overAllSeconds := self asSeconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1550
                    overAllSeconds > 2 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1551
                        overAllSeconds > 10 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1552
                            overAllSeconds > 300 ifTrue:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  1553
                               "/ no decimal above 300 seconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1554
                                fmt := fmt , '%Ss'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1555
                            ] ifFalse:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  1556
                               "/ 1 decimals up to 300 seconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1557
                                fmt := fmt , '%S.%(milli1)s'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1558
                            ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1559
                        ] ifFalse:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  1560
                           "/ 2 decimals up to 10seconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1561
                            fmt := fmt , '%S.%(milli2)s'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1562
                        ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1563
                    ] ifFalse:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  1564
                        "/ millis up to 2seconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1565
                        fmt := fmt , '%S.%is'.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1566
                    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1567
                ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1568
            ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1569
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1570
    ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1571
        fmt isEmpty ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1572
            fmt := '%Ss'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1573
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1574
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1575
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1576
    ^ fmt.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1577
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1578
    "
22817
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
  1579
     3001 seconds formatForPrinting:false
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
  1580
     3001 seconds formatForPrinting:true
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
  1581
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1582
     (TimeDuration fromString:'1w 3d') formatForPrinting
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1583
     (TimeDuration fromString:'1w 3d') printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1584
     (TimeDuration fromString:'7d') printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1585
     (TimeDuration fromString:'6d') printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1586
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1587
     (TimeDuration fromMilliseconds:0.5) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1588
     (TimeDuration fromMilliseconds:0.05) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1589
     (TimeDuration fromMilliseconds:0.005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1590
     (TimeDuration fromMilliseconds:0.0005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1591
     (TimeDuration fromMilliseconds:0.00005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1592
     (TimeDuration fromMilliseconds:0.000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1593
     (TimeDuration fromMilliseconds:0.0000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1594
     (TimeDuration fromMilliseconds:0.00000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1595
     (TimeDuration fromMilliseconds:0.000000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1596
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1597
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:12) formatForPrinting
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  1598
     (TimeDuration hours:0 minutes:0 seconds:2 milliseconds:12) formatForPrinting 
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  1599
     (TimeDuration hours:0 minutes:0 seconds:8 milliseconds:12) formatForPrinting  
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  1600
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:12) formatForPrinting  
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1601
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1602
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1603
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1604
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1605
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1606
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1607
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1608
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1609
     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) formatForPrinting
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1610
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1611
     (TimeDuration hours:0 minutes:38 seconds:22 milliseconds:123) formatForPrinting:true
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1612
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1613
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:0) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1614
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:0) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1615
     (TimeDuration hours:24 minutes:0 seconds:0 milliseconds:0) formatForPrinting
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1616
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1617
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1618
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1619
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1620
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1621
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1622
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1623
     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1624
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1625
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1626
    "Modified: / 18-07-2007 / 14:06:17 / cg"
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  1627
    "Modified (comment): / 17-05-2017 / 16:35:56 / mawalch"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1628
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1629
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1630
getHours
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1631
    "return the number of hours (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1632
     This is the total number of hours - not just the fractional part"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1633
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1634
    ^ self getSeconds // 60 // 60
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1635
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1636
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1637
getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1638
    "return the number of microseconds (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1639
     This is the total number of microseconds - not just the fractional part"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1640
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1641
    ^ (timeEncoding * 1000) + ((additionalPicoseconds ? 0) // (1000 * 1000))
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1642
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1643
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1644
getMilliseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1645
    "return the number of milliseconds (truncated).
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1646
     This is the total number of milliseconds - not just the fractional part"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1647
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1648
    ^ timeEncoding
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1649
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1650
    "Modified: / 18-07-2007 / 13:44:33 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1651
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1652
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1653
getMinutes
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1654
    "return the number of minutes (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1655
     This is the total number of minutes - not just the fractional part"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1656
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1657
    ^ self getSeconds // 60
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1658
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1659
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1660
getNanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1661
    "return the number of nanoseconds (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1662
     This is the total number of nanoseconds - not just the fractional part"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1663
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1664
    ^ (timeEncoding * 1000000) + ((additionalPicoseconds ? 0) // (1000))
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1665
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1666
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1667
getPicoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1668
    "return the number of picoseconds (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1669
     This is the total number of picoseconds - not just the fractional part"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1670
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1671
    ^ (timeEncoding * 1000000000) + ((additionalPicoseconds ? 0))
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1672
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1673
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1674
getSeconds
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1675
    "return the number of seconds (truncated).
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1676
     This is the total number of seconds - not just the fractional part"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1677
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1678
    ^ timeEncoding // 1000
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1679
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1680
    "Modified: / 18-07-2007 / 13:44:37 / cg"
22281
e7b51a58d9b4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22255
diff changeset
  1681
    "Modified (comment): / 21-09-2017 / 18:50:03 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1682
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1683
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1684
possiblyNegatedValueFromTimeEncodingInto:aBlock
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1685
    timeEncoding < 0 ifTrue:[
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1686
        ^ (aBlock value:(timeEncoding negated)) negated
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1687
    ].    
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1688
    ^ aBlock value:timeEncoding
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1689
!
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1690
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1691
setHours:h minutes:m seconds:s millis:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1692
    <resource: #obsolete>
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1693
    "set my time given individual values"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1694
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1695
    self obsoleteMethodWarning:'use setHours:minutes:seconds:milliseconds:'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1696
    self setHours:h minutes:m seconds:s milliseconds:millis.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1697
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1698
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1699
setHours:h minutes:m seconds:s milliseconds:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1700
    "set my time given individual values"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1701
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1702
    self setMilliseconds:((h * 60 * 60 ) + (m * 60) + s) * 1000 + millis.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1703
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1704
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1705
setMicroseconds:micros
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1706
    "set my duration given microseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1707
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1708
    |restMicros|
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1709
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1710
    micros isInteger ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1711
        timeEncoding := micros // 1000.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1712
        additionalPicoseconds := (micros \\ 1000) * 1000 * 1000
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1713
    ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1714
        timeEncoding := micros // 1000.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1715
        restMicros := micros - (timeEncoding * 1000).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1716
        additionalPicoseconds := (restMicros * 1000 * 1000) rounded asInteger.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1717
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1718
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1719
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1720
     self new setMicroseconds:100
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1721
     self new setMicroseconds:2
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1722
     self new setMicroseconds:1.5
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1723
     self new setMicroseconds:0.1
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1724
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1725
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1726
    "Modified: / 18-07-2007 / 13:44:16 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1727
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1728
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1729
setMilliseconds:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1730
    "set my duration given milliseconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1731
     Duration can be longer than a day"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1732
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1733
    |rest|
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1734
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1735
    millis isInteger ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1736
        timeEncoding := millis.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1737
    ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1738
        timeEncoding := millis truncated.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1739
        rest := millis - timeEncoding.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1740
        additionalPicoseconds := (rest * 1000 * 1000 * 1000) rounded asInteger.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1741
    ]
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1742
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1743
    "Modified: / 18-07-2007 / 13:44:16 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1744
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1745
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1746
setNanoseconds:nanos
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1747
    "set my duration given nanoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1748
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1749
    |restNanos|
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1750
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1751
    nanos isInteger ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1752
        timeEncoding := nanos // 1000000.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1753
        additionalPicoseconds := (nanos \\ 1000) * 1000 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1754
    ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1755
        timeEncoding := nanos // (1000*1000).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1756
        restNanos := nanos - (timeEncoding * (1000*1000)).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1757
        additionalPicoseconds := (restNanos * 1000) rounded asInteger.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1758
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1759
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1760
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1761
     self new setMicroseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1762
     self new setNanoseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1763
     self new setNanoseconds:0.1
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1764
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1765
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1766
    "Modified: / 18-07-2007 / 13:44:16 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1767
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1768
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1769
setPicoseconds:picos
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1770
    "set my duration given picoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1771
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1772
    timeEncoding := picos // (1000 * 1000 * 1000).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1773
    additionalPicoseconds := (picos \\ (1000 * 1000 * 1000)) rounded asInteger.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1774
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1775
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1776
     self new setMicroseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1777
     self new setNanoseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1778
     self new setPicoseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1779
     self new setPicoseconds:4.5
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1780
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1781
     self assert: (self new setPicoseconds:4000) = (self new setNanoseconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1782
     self assert: (self new setPicoseconds:4000000) = (self new setNanoseconds:4000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1783
     self assert: (self new setPicoseconds:4000000) = (self new setMicroseconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1784
     self assert: (self new setPicoseconds:4000000000) = (self new setNanoseconds:4000000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1785
     self assert: (self new setPicoseconds:4000000000) = (self new setMicroseconds:4000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1786
     self assert: (self new setPicoseconds:4000000000) = (self new setMilliseconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1787
     self assert: (self new setPicoseconds:4000000000000) = (self new setMilliseconds:4000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1788
     self assert: (self new setPicoseconds:4000000000000) = (self new setMicroseconds:4000000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1789
     self assert: (self new setPicoseconds:4000000000000) = (self new setNanoseconds:4000000000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1790
     self assert: (self new setPicoseconds:4000000000000) = (self new setSeconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1791
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1792
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1793
    "Modified: / 18-07-2007 / 13:44:16 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1794
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1795
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1796
setSeconds:secs
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1797
    "set my timeduration given seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1798
     Notice that (in contrast to Time), there is no modulu operation here.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1799
     Duration can be longer than a day, and (much) smaller than a second"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1800
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1801
    self setMilliseconds:(secs * 1000).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1802
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1803
    "Modified: / 18-07-2007 / 13:44:24 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1804
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1805
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1806
!TimeDuration methodsFor:'testing'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1807
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1808
isTimeDuration
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1809
    ^ true
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1810
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1811
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1812
isZero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1813
    ^ self = self class zero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1814
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1815
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1816
negative
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1817
    ^ timeEncoding < 0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1818
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1819
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1820
!TimeDuration class methodsFor:'documentation'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1821
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1822
version
18564
55bd2aa4d56e class: TimeDuration
Claus Gittinger <cg@exept.de>
parents: 17388
diff changeset
  1823
    ^ '$Header$'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1824
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1825
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1826
version_CVS
18564
55bd2aa4d56e class: TimeDuration
Claus Gittinger <cg@exept.de>
parents: 17388
diff changeset
  1827
    ^ '$Header$'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1828
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1829
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1830
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1831
TimeDuration initialize!