TimeDuration.st
author Claus Gittinger <cg@exept.de>
Wed, 18 Dec 2019 19:05:01 +0100
changeset 25155 5ab0366fbef0
parent 24893 373cc0ac5f71
child 25156 0dacbf3f67d7
permissions -rw-r--r--
regenerated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
     1
"{ Encoding: utf8 }"
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
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
"
22868
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    43
    Represents a time/timestamp difference.
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    44
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    45
    The resolution is 1 ps.
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    46
    However, such small timedurations are usually only created by physical computations
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    47
    (see goodies/physic).
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    48
    The typical OS-time resolution is in the milli- or microsecond range.
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    49
    External logging hardware may generate timestamps in the micro- or nanosecond range.
b8cf1f0e0e65 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22866
diff changeset
    50
    Picosecond resolution should be good enough for almost any application (at least for the near future).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
22870
c629e025c96b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22868
diff changeset
    52
    Most timedurations only require/have millisecond resolution,
c629e025c96b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22868
diff changeset
    53
    so the pico instvar is nil/0 and does not require an aditional largeInteger operation.
c629e025c96b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22868
diff changeset
    54
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    DefaultFormatForPrinting    if non-nil, allows for the variable printFormat to be overwritten
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
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
!TimeDuration class methodsFor:'instance creation'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
days:d 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    "return a new TimeDuration representing a duration of d days."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    d == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    ^ self hours:(d*24) minutes:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
     TimeDuration days:1  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
days:d hours:h minutes:m seconds:s 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    "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
    74
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    ^ self basicNew 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
        setHours:(d*24)+h minutes:m seconds:s milliseconds:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
     TimeDuration days:1  hours:2 minutes:33 seconds:0   
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
     TimeDuration days:4 hours:100 minutes:33 seconds:0   
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
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
fromHours:hoursInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    "return a new TimeDuration representing a duration of n hours."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    ^ self new setSeconds:(hoursInterval * (60*60))
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
     TimeDuration fromHours:8  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    95
fromMicroseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    96
    "return a new TimeDuration representing a duration of n microseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    97
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    98
    ^ self new setMicroseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
    99
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   100
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   101
     TimeDuration fromMicroseconds:500  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   102
     500 microseconds  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   103
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   104
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   105
    "Created: / 18-07-2007 / 13:56:25 / cg"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   106
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   107
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
fromMilliseconds:n
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    "return a new TimeDuration representing a duration of n milliseconds."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "redefined to disable wrapping at 24hours."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    ^ self new setMilliseconds:n
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
     TimeDuration fromMilliseconds:500  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
     500 milliseconds  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    "Created: / 18-07-2007 / 13:56:25 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
fromMinutes:minutesInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    "return a new TimeDuration representing a duration of n minutes."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    ^ self new setSeconds:(minutesInterval * 60)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
     TimeDuration fromMinutes:120  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   132
fromNanoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   133
    "return a new TimeDuration representing a duration of n nanoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   134
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   135
    ^ self new setNanoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   136
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
     TimeDuration fromNanoseconds:500  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   139
     500 nanoseconds  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   140
    "
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
fromPicoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   144
    "return a new TimeDuration representing a duration of n picoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   145
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   146
    ^ self new setPicoseconds:n
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   147
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   148
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   149
     TimeDuration fromPicoseconds:500  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   150
     500 picoseconds  
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   151
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   152
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   153
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
fromSeconds:secondsInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    "return a new TimeDuration representing a duration of n seconds."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    "redefined to disable wrapping at 24hours."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    ^ self new setSeconds:secondsInterval
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
     TimeDuration fromSeconds:3600  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
hours:h
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    "return a new TimeDuration representing a duration of h hours.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    h == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    ^ self basicNew setHours:h minutes:0 seconds:0 milliseconds:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
     TimeDuration hours:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
     TimeDuration hours:100  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    "Created: / 14-07-2007 / 18:15:51 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
hours:h minutes:m seconds:s millis:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    <resource: #obsolete>
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
    "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
   183
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    self obsoleteMethodWarning:'use hours:minutes:seconds:milliseconds:'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
    ^ self hours:h minutes:m seconds:s milliseconds:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
     TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
     TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   194
microseconds:microseconds
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   195
    "return a new TimeDuration representing a duration of microseconds microseconds.
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
   196
     Now we support microseconds (even picoseconds) but we still round to milliseconds for backward
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
   197
     compatibility with the historic interface."
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   198
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   199
    microseconds == 0 ifTrue:[^ TimeDurationZero].
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   200
    ^ self basicNew setMilliseconds:((microseconds / 1000) rounded).
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   201
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   202
    "
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   203
     TimeDuration microseconds:2499 
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   204
     TimeDuration microseconds:2500 
18564
55bd2aa4d56e class: TimeDuration
Claus Gittinger <cg@exept.de>
parents: 17388
diff changeset
   205
     TimeDuration microseconds:12345678900 
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   206
    "
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
   207
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
   208
    "Modified (comment): / 22-05-2018 / 16:54:17 / Stefan Vogel"
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   209
!
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   210
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
milliseconds:m
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    "return a new TimeDuration representing a duration of m millis.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    m == 0 ifTrue:[^ TimeDurationZero].
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   216
    ^ self basicNew setMilliseconds:m
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
     TimeDuration milliseconds:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
minutes:m
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    "return a new TimeDuration representing a duration of m minutes.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    m == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    ^ self basicNew setHours:0 minutes:m seconds:0 milliseconds:0
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
     TimeDuration minutes:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    "Created: / 06-08-2007 / 15:32:42 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   237
readFrom:aStringOrStream defaultUnit:defaultUnitOrNilArg onError:exceptionBlock
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    "return a new TimeDuration, reading a printed representation from aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
     The format is either:
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   240
        [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
   241
                 ([n 'ms'] | [n 'us'] | [n 'ns'] | [n 'ps'])
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
        where 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
            yr -> year
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
            mon -> month
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
            w -> week
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
            d -> day
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
            h -> hour
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
            m -> minutes
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
            s -> seconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   250
            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
   251
            us -> microseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   252
            ns -> nanoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   253
            ps -> picoseconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
     or:
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   255
        h:m:s.<ms2>
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   256
        h:m:s.<fract>
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
     The yr and mon specifiers stand for 365d and 30d respectively.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
     If defaultUnitOrNil is non-nil, a plain number is treated as that;
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
     otherwise, a plain number raises an error.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   261
     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
   262
     or the whole duration may be negative, as in '-(1h 10m)'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
    ^ [
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   266
        |seconds millis picos restMillis 
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   267
         t1 str val fraction mantissa uIdx unit unitChar1 negative defaultUnitOrNil|
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   269
        defaultUnitOrNil := defaultUnitOrNilArg.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
        str := aStringOrStream readStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
        seconds := 0.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
        millis := 0.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   273
        picos := 0.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   274
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   275
        negative := false.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   276
        str peek == $- ifTrue:[
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   277
            str next.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   278
            str peek == $( ifTrue:[
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   279
                |t|
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   280
                str next.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   281
                t := self readFrom:str defaultUnit:defaultUnitOrNil onError:[^ exceptionBlock value].
24808
6fe4d0ddbfa2 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24781
diff changeset
   282
                str skipSeparators == $) ifTrue:[
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   283
                    str next.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   284
                    ^ t negated.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   285
                ].
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   286
                ^ exceptionBlock value.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   287
            ].                
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   288
            negative := true.
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   289
        ].
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   290
        
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
        [
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
            |nextCh|
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
            val := Integer readFrom:str onError:nil.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
            val isNil ifTrue:[^ exceptionBlock value].
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   296
            negative ifTrue:[ val := val negated. negative := false. ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
            str peek == $: ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
                "/ hour:minutes format
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
                str next.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
                seconds := val*3600.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
                val := Integer readFrom:str onError:nil.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
                val isNil ifTrue:[^ exceptionBlock value].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
                seconds := seconds + (val*60).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
                str peek == $: ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
                    "/ hour:minutes:seconds format
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
                    str next.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
                    val := Integer readFrom:str onError:nil.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
                    val isNil ifTrue:[^ exceptionBlock value].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
                    seconds := seconds + val.
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   310
                    (str peek == $. or:[str peek == $,]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
                        "/ hour:minutes:seconds.millis format
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
                        str next.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   313
                        "/ 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
   314
                        "/ 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
   315
                        "/ thus: count the zeros...
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   316
                        str peek isDigit ifTrue:[
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   317
                            "/ fraction := Number readMantissaFrom:str radix:10.
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   318
                            "/ fraction isNil ifTrue:[^ exceptionBlock value].
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   319
                            "/ ignore the float value; take the fraction
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   320
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   321
                            mantissa := Number readMantissaAndScaleFrom:str radix:10.
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   322
                            fraction := (mantissa at:2) / (10 raisedTo:(mantissa at:3)).
22858
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   323
                            (mantissa at:3) > 3 ifTrue:[
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   324
                                picos := fraction * (1000 * 1000 * 1000 * 1000).
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   325
                                millis := picos // (1000 * 1000 * 1000).
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   326
                                picos := picos \\ (1000 * 1000 * 1000).
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   327
                            ] ifFalse:[
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   328
                                millis := fraction * 1000.
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   329
                            ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   330
                        ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   331
                            millis := 0
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   332
                        ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
                    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
                ].
22858
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   335
                t1 := self fromMilliseconds:(seconds*1000+millis).
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   336
                picos notNil ifTrue:[
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   337
                    t1 additionalPicoseconds:picos
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   338
                ].
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
   339
                ^ t1
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
            ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   341
            ((str peek == $.) or:[(str peek == $,)]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
                str next.
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   343
                "/ fraction := Number readMantissaFrom:str radix:10.
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   344
                "/ ignore the float value; take the fraction
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   345
                mantissa := Number readMantissaAndScaleFrom:str radix:10.
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
   346
                fraction := (mantissa at:2) / (10 raisedTo:(mantissa at:3)).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
                val := val + fraction.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
            str skipSeparators.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
            str atEnd ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
                defaultUnitOrNil isNil ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
                    ^ exceptionBlock value
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
                "/ no unit given - assume defaultUnit
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
                unitChar1 := defaultUnitOrNil.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   356
                "/ can be only used for one number
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   357
                defaultUnitOrNil := nil.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
            ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
                unitChar1 := str next.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
            str atEnd ifFalse:[ 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
                nextCh := str peek
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   366
            "/ milli, micro, nano and pico
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
   367
            unitChar1 == $µ ifTrue:[ unitChar1 := $u].
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   368
            uIdx := 'munp' indexOf:unitChar1.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   369
            ((uIdx ~~ 0) and:[nextCh == $s]) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   370
                unitChar1 == $m ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   371
                    millis := millis + val.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
                ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
                    unit := #(
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   374
                          1000000       "us" 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   375
                          1000          "ns" 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   376
                          1             "ps" 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   377
                          ) at:uIdx-1.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   378
                    picos := (unit * val).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   379
                    millis := picos // (1000 * 1000 * 1000).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   380
                    picos := picos \\ (1000 * 1000 * 1000).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
                ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   382
            ] ifFalse:[
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   383
                uIdx := 'ywdhms' indexOf:unitChar1.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   384
                uIdx == 0 ifTrue:[^ exceptionBlock value].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   385
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   386
                (unitChar1 == $m and:[nextCh == $s]) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   387
                    millis := millis + val.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   388
                ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   389
                    (unitChar1 == $m and:[nextCh == $o]) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   390
                        unit := 2592000 "24*60*60*30"     "mon"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   391
                    ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   392
                        unit := #(
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   393
                                  31536000 "24*60*60*365" "yr"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   394
                                  604800 "24*60*60*7"     "w"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   395
                                  86400  "24*60*60"       "d"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   396
                                  3600                    "h"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   397
                                  60                      "m"
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   398
                                  1 ) at:uIdx.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   399
                    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   400
                    seconds := seconds + (unit * val).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   401
                ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
            ].
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   403
            [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
   404
            str skipSeparators.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   405
            "/ done when at the end or a $) is to be read
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   406
            str atEnd or:[aStringOrStream isString not and:[str peek == $)]]
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
        ] whileFalse.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   408
        millis := (seconds*1000) + millis.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   409
        restMillis := millis - millis truncated.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   410
        millis := millis truncated.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   411
        picos := picos + (restMillis * 1000 * 1000 * 1000) truncated. 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   412
        millis := millis + (picos // (1000*1000*1000)).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   413
        picos := picos \\ (1000*1000*1000).
22856
e8a1e761cdcd fix stc compiler error
Stefan Vogel <sv@exept.de>
parents: 22843
diff changeset
   414
        t1 := self fromMilliseconds:millis asInteger.
e8a1e761cdcd fix stc compiler error
Stefan Vogel <sv@exept.de>
parents: 22843
diff changeset
   415
        t1 additionalPicoseconds:picos.
e8a1e761cdcd fix stc compiler error
Stefan Vogel <sv@exept.de>
parents: 22843
diff changeset
   416
        t1
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   417
    ] on:Error do:[:ex |
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
        |t|
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
        "/ retry, using inherited readFrom (Object-storeString)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
        t := Object readFrom:aStringOrStream onError:[^ exceptionBlock value].
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   422
        (t isTimeDuration) ifFalse:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
            ^ exceptionBlock value
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
        t
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
    "
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   429
     TimeDuration readFrom:'2' defaultUnit:$h onError:nil -> 2h
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   430
     TimeDuration readFrom:'100' defaultUnit:$m onError:nil -> 1h 40m
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   431
     TimeDuration readFrom:'100' defaultUnit:$s onError:nil -> 1m 40s
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   432
     TimeDuration readFrom:'0200' defaultUnit:$h onError:nil -> 1w 1d 8h
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
     TimeDuration readFrom:'1h'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
     TimeDuration readFrom:'1h 35m'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
     TimeDuration readFrom:'25h'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
     TimeDuration readFrom:'3d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
     TimeDuration readFrom:'1w'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
     TimeDuration readFrom:'120s'     
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   440
     TimeDuration readFrom:'1500ms'    
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
     TimeDuration readFrom:'3ms'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
     TimeDuration readFrom:'1yr 5d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
     TimeDuration readFrom:'1mon'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
     TimeDuration readFrom:'05:10'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
     TimeDuration readFrom:'05:10:5'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
     TimeDuration readFrom:'05:10:5.150'  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   448
     TimeDuration readFrom:'-1h'
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   449
     TimeDuration readFrom:'-1h 10m'
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   450
     TimeDuration readFrom:'1h -10m'
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   451
     TimeDuration readFrom:'-(1h 10m)' 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   452
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   453
     TimeDuration readFrom:'1ms' -> 1ms 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   454
     TimeDuration readFrom:'5us' 
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
   455
     TimeDuration readFrom:'5µs' 
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   456
     TimeDuration readFrom:'5ns' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   457
     TimeDuration readFrom:'5ps' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   458
     TimeDuration readFrom:'5005 ps' 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   459
     TimeDuration readFrom:'1.01 s' -> 1.010s 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   460
     TimeDuration readFrom:'1.001 s' -> 1.001s 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   461
     TimeDuration readFrom:'1.0001 s' -> 1.0001s 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   462
     TimeDuration readFrom:'1s 5ns' -> 1.000000005s
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   463
     (TimeDuration readFrom:'1s 5ns') = (TimeDuration fromNanoseconds:(5+1000000000))
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   464
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
     TimeDuration readFrom:(TimeDuration new storeString)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
    "Modified: / 08-10-2007 / 16:41:48 / cg"
24808
6fe4d0ddbfa2 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 24781
diff changeset
   469
    "Modified: / 28-09-2019 / 15:23:14 / Stefan Vogel"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
readFrom:aStringOrStream onError:exceptionBlock
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
    "return a new TimeDuration, reading a printed representation from aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
     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
   475
     where 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
            yr -> year
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
            mon -> month
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
            w -> week
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
            d -> day
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
            h -> hour
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
            m -> minutes
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
            s -> seconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
            ms -> milliseconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
     The yr and mon specifiers stand for 365d and 30d respectively.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
     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
   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
    ^ self readFrom:aStringOrStream defaultUnit:$s onError:exceptionBlock
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
     TimeDuration readFrom:'100' onError:nil      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
     TimeDuration readFrom:'100' defaultUnit:$m onError:nil 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
     TimeDuration readFrom:'1h'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
     TimeDuration readFrom:'1h 35m'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
     TimeDuration readFrom:'25h'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
     TimeDuration readFrom:'3d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
     TimeDuration readFrom:'1w'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
     TimeDuration readFrom:'120s'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
     TimeDuration readFrom:'1500ms    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
     TimeDuration readFrom:'3ms'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
     TimeDuration readFrom:'1yr 5d'     
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
     TimeDuration readFrom:'1mon'     
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
    "Modified: / 08-10-2007 / 16:41:48 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
seconds:s
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
    "return a new TimeDuration representing a duration of s seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
     See also Time now / Date today / Timestamp now."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
    s == 0 ifTrue:[^ TimeDurationZero].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   515
    ^ self basicNew setMilliseconds:(s * 1000)
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
     TimeDuration seconds:2 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
    "Created: / 06-08-2007 / 15:32:21 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
weeks:w 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
    "return a new TimeDuration representing a duration of w weeks."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    ^ self days:(w * 7)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
     TimeDuration weeks:1  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
    "Created: / 05-09-2011 / 11:18:27 / cg"
24113
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   534
!
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   535
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   536
years:y 
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   537
    "return a new TimeDuration representing a duration of y years."
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   538
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   539
    ^ self days:(y * 365)
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   540
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   541
    "
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   542
     TimeDuration years:1  
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   543
    "
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   544
58d2044ec761 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23929
diff changeset
   545
    "Created: / 08-05-2019 / 12:42:16 / Claus Gittinger"
16356
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:'class initialization'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   549
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   550
initialize
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   551
    TimeDurationZero isNil ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   552
        TimeDurationZero := self basicNew setHours:0 minutes:0 seconds:0 milliseconds:0.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   553
    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   554
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
    "Modified: / 10-05-2011 / 10:31:35 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
!TimeDuration class methodsFor:'constants'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
zero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
    "return the neutral element for addition (0s)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
    ^ TimeDurationZero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
    "Modified: 18.7.1996 / 12:26:12 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
!TimeDuration class methodsFor:'format strings'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
defaultFormatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
    ^  DefaultFormatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
defaultFormatForPrinting:aString
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
    DefaultFormatForPrinting := aString
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
formatString12us
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
    "return the format string used to format US times (and other areas)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
    ^ '%h:%m:%s.%i'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
formatString24
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
    "return the format string used to format european times (and other areas)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
    ^ '%h:%m:%s.%i'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
!TimeDuration class methodsFor:'timing evaluation'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
toRun:aBlock
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
    "return the TimeDuration it takes to execute aBlock.                          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
     A modern variant of Time millisecondsToRun: (which prints itself nicely)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   596
    ^ self microseconds:(Time microsecondsToRun:aBlock).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
     TimeDuration toRun:[ 20000 factorial ]     
16872
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   600
     TimeDuration toRun:[ 2000 factorial ]     
3fef76482bfc class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16830
diff changeset
   601
     TimeDuration toRun:[ 900 factorial ]     
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
22918
ed09bf19e476 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22917
diff changeset
   605
!TimeDuration methodsFor:'Compatibility-Squeak'!
ed09bf19e476 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22917
diff changeset
   606
ed09bf19e476 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22917
diff changeset
   607
wait
24365
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   608
    "wait the receiver's timeDuration"
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   609
    
22918
ed09bf19e476 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22917
diff changeset
   610
    Delay waitFor:self
24365
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   611
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   612
    "
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   613
     5 seconds wait
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   614
    "
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   615
b0e21078359c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24159
diff changeset
   616
    "Modified (comment): / 26-06-2019 / 11:35:02 / Claus Gittinger"
22918
ed09bf19e476 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22917
diff changeset
   617
! !
ed09bf19e476 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22917
diff changeset
   618
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
!TimeDuration methodsFor:'accessing'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   620
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
days
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   622
    "get the (truncated) total number of days.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   623
     Use this only for printing.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   624
     Sigh: this is inconsistent: hours, minutes, seconds etc. 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   625
     return the fraction, not the total"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   626
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   627
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   628
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   629
            t // 1000 // 3600 // 24
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   630
        ].    
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   631
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   632
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   633
     (Duration fromString:'1mon 1d 4h 3m 5s 10ms') days
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   634
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   635
     (Duration days:9 hours:1 minutes:2 seconds:3) days   
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   636
     (Duration days:-9 hours:-1 minutes:-2 seconds:-3) days 
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   637
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   638
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   639
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   640
hours
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   641
    "get the (truncated) number of hours.
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   642
     notice: that is NOT the total number of hours,
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   643
     but the fractional part only. 
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   644
     Use this only for printing"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   645
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   646
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   647
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   648
            (t // 1000 // 3600 \\ 24)
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   649
        ]
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   650
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   651
     (Duration fromString:'1d 4h 3m 5s 10ms') hours
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   652
     (Duration fromString:'1d 4h 3m 1s 10ms') getHours
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   653
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   654
     (Duration days: 9 hours: 1 minutes: 2 seconds: 3) hours
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   655
     (Duration days: -9 hours: -1 minutes: -2 seconds: -3) hours
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   656
    "
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   657
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   658
    "Modified (comment): / 21-09-2017 / 18:53:32 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   659
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   660
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   661
milliseconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   662
    "get the milliseconds part 
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   663
     notice: that is NOT the total number of millis,
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   664
     but the fractional part (within the second) only. 
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   665
     Use this only for printing.
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   666
     asMilliseconds is probably what you want"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   667
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   668
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   669
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   670
            t \\ 1000
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   671
        ].    
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
     (Duration milliseconds:10) milliseconds
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   674
     (Duration milliseconds:-10) milliseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   675
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   676
     (Duration fromString:'1s 10ms') milliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   677
     (Duration fromString:'1s 10ms') getMilliseconds
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   678
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   679
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   680
    "Modified: / 05-05-2010 / 14:22:04 / cg"
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   681
    "Modified (comment): / 21-09-2017 / 18:53:26 / 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
minutes
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   685
    "get the number of minutes.
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   686
     notice: that is NOT the total number of minutes,
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   687
     but the fractional part only. 
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   688
     Use this only for printing"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   689
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   690
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   691
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   692
            t // 1000 // 60 \\ 60
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   693
        ]
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
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   696
     (Duration fromString:'1h 3m 5s 10ms') minutes
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   697
     (Duration fromString:'1h 3m 1s 10ms') getMinutes
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   698
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   699
     (Duration days: 9 hours: 1 minutes: 2 seconds: 3) minutes
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   700
     (Duration days: -9 hours: -1 minutes: -2 seconds: -3) minutes
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   701
    "
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   702
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   703
    "Modified (comment): / 21-09-2017 / 18:53:22 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   704
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   705
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   706
picoseconds
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   707
    "get the optional additional picoseconds (0..999999999)
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   708
     notice: that is NOT the total number of picoseconds,
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   709
     but the fractional part (within the second) only. 
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   710
     Use this only for printing."
22620
c77e738e5d23 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22519
diff changeset
   711
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   712
    ^ (self milliseconds * 1000 * 1000 * 1000) + (additionalPicoseconds ? 0)
22620
c77e738e5d23 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22519
diff changeset
   713
!
c77e738e5d23 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22519
diff changeset
   714
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   715
seconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   716
    "get the number of seconds.
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
   717
     notice: that is NOT the total number of seconds,
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   718
     but the fractional part only. 
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   719
     Use this only for printing.
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   720
     asSeconds is probably what you want"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   721
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   722
    ^ self 
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   723
        possiblyNegatedValueFromTimeEncodingInto:[:t |
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   724
            t // 1000 \\ 60
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   725
        ]
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   726
        
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   727
    "
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
   728
     (TimeDuration fromString:'1m 5s 10ms') seconds
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
   729
     (TimeDuration fromString:'1m 1s 10ms') getSeconds
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
   730
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
   731
     (TimeDuration days: 9 hours: 1 minutes: 2 seconds: 3) seconds
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
   732
     (TimeDuration days: -9 hours: -1 minutes: -2 seconds: -3) seconds
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   733
    "
22284
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   734
e6aaf78f69d6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22281
diff changeset
   735
    "Modified (comment): / 21-09-2017 / 18:53:13 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   736
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   737
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   738
!TimeDuration methodsFor:'arithmetic'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   739
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   740
* aNumber
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   741
    "return a new scaled timeDuration"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   742
19022
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   743
    aNumber isNumber ifTrue:[
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   744
        ^ self species basicNew 
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   745
            setMilliseconds:(timeEncoding * aNumber)
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   746
            additionalPicoseconds:(additionalPicoseconds ? 0) * aNumber.
19022
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   747
    ].
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   748
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   749
    "/ notice: although noone seems to implement it (currently),
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   750
    "/ there are additional packages which add support (i.e. goodies/physic),
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   751
    "/ so do not remove the call below.
19022
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   752
    ^ aNumber productFromTimeDuration:self
1d3173b3a291 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18564
diff changeset
   753
    
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   754
    "
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   755
     5 c* (TimeDuration fromString:'10s')
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   756
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   757
     (TimeDuration fromString:'10s') * 5
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   758
     (TimeDuration fromString:'10s') * 10
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   759
     (TimeDuration fromString:'10s') * 100
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   760
     (TimeDuration fromString:'10s') * 1000
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
   761
     (TimeDuration fromString:'-10s') * 1000
22621
ea38224ef388 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22620
diff changeset
   762
     (TimeDuration fromString:'10s') * (TimeDuration fromString:'10s')
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   763
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   764
     (TimeDuration fromString:'10ms') * 5
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
   765
     (TimeDuration fromString:'10us') * 5
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   766
    "
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   767
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   768
    "Modified: / 27-07-2018 / 10:32:02 / Stefan Vogel"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   769
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   770
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   771
+ aTimeDurationOrNumberOfSeconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   772
    "return a new timeDuration.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   773
     The argument may be a timeDuration or
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   774
     a number, which is interpreted as seconds."
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   775
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   776
    |newMillis newPicos|
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   777
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   778
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   779
        newMillis := timeEncoding + (aTimeDurationOrNumberOfSeconds * 1000) asInteger.
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   780
        newPicos := additionalPicoseconds ? 0.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   781
        ^ self species basicNew
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   782
            setMilliseconds:newMillis additionalPicoseconds:newPicos
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   783
    ].
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   784
    ^ aTimeDurationOrNumberOfSeconds sumFromTimeDuration:self.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   785
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   786
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   787
     (TimeDuration fromString:'1m') + (TimeDuration fromString:'10s') 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   788
     1 minutes - 10 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   789
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   790
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   791
    "Created: / 25-07-2018 / 20:58:17 / Stefan Vogel"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   792
    "Modified: / 27-07-2018 / 10:32:21 / Stefan Vogel"
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   793
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   794
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   795
- aTimeDurationOrNumberOfSeconds
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   796
    "return a new timeDuration.
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   797
     The argument may be a timeDuration or
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   798
     a number, which is interpreted as seconds."
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   799
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   800
    |newMillis newPicos|
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   801
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   802
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   803
        newMillis := timeEncoding - (aTimeDurationOrNumberOfSeconds * 1000) asInteger.
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   804
        newPicos := additionalPicoseconds ? 0.
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   805
        ^ self species basicNew
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   806
            setMilliseconds:newMillis additionalPicoseconds:newPicos
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   807
    ].
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   808
    ^ aTimeDurationOrNumberOfSeconds differenceFromTimeDuration:self.
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   809
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   810
    "
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   811
     (TimeDuration fromString:'1m') - (TimeDuration fromString:'10s') 
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   812
     1 minutes - 10 seconds
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   813
    "
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
   814
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   815
    "Modified: / 27-07-2018 / 10:32:29 / Stefan Vogel"
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   816
!
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   817
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   818
/ aTimeDurationOrNumberOfSeconds
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   819
    "if the argument is a number, return a new timeDuration.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   820
     Otherwise, return the quotient as a number."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   821
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   822
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   823
        ^ self species basicNew 
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   824
            setMilliseconds:(timeEncoding / aTimeDurationOrNumberOfSeconds)
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   825
            additionalPicoseconds:((additionalPicoseconds?0) / aTimeDurationOrNumberOfSeconds).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   826
    ].
19023
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   827
    aTimeDurationOrNumberOfSeconds isTimeDuration ifTrue:[
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   828
        ^ self getPicoseconds / aTimeDurationOrNumberOfSeconds getPicoseconds.
19023
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   829
    ].
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   830
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   831
    "/ notice: although noone seems to implement it (currently),
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   832
    "/ there are additional packages which add support (i.e. goodies/physic),
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
   833
    "/ so do not remove the call below.
19023
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   834
    ^ aTimeDurationOrNumberOfSeconds quotientFromTimeDuration:self
b2cd3ed0cb02 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 19022
diff changeset
   835
    
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   836
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   837
     (TimeDuration fromString:'10s') / (TimeDuration fromString:'5s')
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   838
     (TimeDuration fromString:'10s') / 5
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   839
    "
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   840
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
   841
    "Modified (format): / 27-07-2018 / 10:38:07 / Stefan Vogel"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   842
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   843
22917
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   844
// aTimeDurationOrNumberOfSeconds
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   845
    "if the argument is a number, return a new timeDuration.
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   846
     Otherwise, return the quotient as a number."
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   847
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   848
    aTimeDurationOrNumberOfSeconds isNumber ifTrue:[
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   849
        ^ self species basicNew 
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   850
            setSeconds:(self getSeconds // aTimeDurationOrNumberOfSeconds)
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   851
    ].
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   852
    aTimeDurationOrNumberOfSeconds isTimeDuration ifTrue:[
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   853
        ^ (self getSeconds // aTimeDurationOrNumberOfSeconds getSeconds)
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   854
    ].
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   855
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   856
    "/ notice: although noone seems to implement it (currently),
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   857
    "/ there are additional packages which add support (i.e. goodies/physic),
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   858
    "/ so do not remove the call below.
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   859
    ^ (aTimeDurationOrNumberOfSeconds quotientFromTimeDuration:self) truncated
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   860
    
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   861
    "
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   862
     (TimeDuration fromString:'10s') // (TimeDuration fromString:'3')
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   863
     (TimeDuration fromString:'10s') // 3
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   864
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   865
     (TimeDuration fromString:'10s') / (TimeDuration fromString:'3')
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   866
     (TimeDuration fromString:'10s') / 3
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   867
    "
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   868
!
cefccd43b35a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22891
diff changeset
   869
16403
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   870
abs
22866
43f44339eee0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22865
diff changeset
   871
    ^ self class new setMilliseconds:(self asExactMilliseconds abs)
16403
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   872
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   873
    "
22865
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   874
     (TimeDuration fromSeconds:3600) abs
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   875
     (TimeDuration fromSeconds:-3600) abs
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   876
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   877
     (TimeDuration fromSeconds:20000) abs
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   878
     (TimeDuration fromSeconds:-20000) abs
16403
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   879
    "
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   880
!
ddd36af8ddd7 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16357
diff changeset
   881
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   882
negated
22866
43f44339eee0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22865
diff changeset
   883
    ^ self class new setMilliseconds:(self asExactMilliseconds) negated
22865
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   884
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   885
    "
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   886
     50 nanoseconds negated asNanoseconds
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   887
     1 seconds negated asSeconds
77d1d90b53bc #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22864
diff changeset
   888
    "
23929
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   889
!
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   890
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   891
squared
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   892
    "answer a  float representing my value in seconds - squared.
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   893
     Used to compute e.g. variance and standard deviation."
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   894
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   895
    ^ self secondsAsFloat squared
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   896
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   897
    "
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   898
     50 nanoseconds squared 
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   899
     1 seconds squared
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   900
    "
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   901
322b5ee4229b #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23238
diff changeset
   902
    "Created: / 15-03-2019 / 17:57:50 / Stefan Vogel"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   903
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   904
24159
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   905
!TimeDuration methodsFor:'comparing'!
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   906
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   907
< something
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   908
    |otherTimeEncoding|
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   909
    
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   910
    something class == self class ifTrue:[
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   911
        otherTimeEncoding :=something timeEncoding.
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   912
        timeEncoding = otherTimeEncoding ifTrue:[
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   913
            ^ (additionalPicoseconds ? 0) < something additionalPicoseconds
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   914
        ].    
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   915
        ^ timeEncoding < otherTimeEncoding
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   916
    ].    
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   917
    ^ super < something
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   918
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   919
    "Created: / 26-05-2019 / 10:02:59 / Claus Gittinger"
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   920
!
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   921
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   922
= something
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   923
    something class == self class ifTrue:[
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   924
        ^ timeEncoding = something timeEncoding
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   925
        and:[(additionalPicoseconds ? 0) = something additionalPicoseconds]
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   926
    ].    
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   927
    ^ super = something
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   928
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   929
    "Created: / 26-05-2019 / 09:40:44 / Claus Gittinger"
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   930
!
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   931
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   932
hash
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   933
    ^ timeEncoding bitXor:(additionalPicoseconds ? 0)
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   934
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   935
    "Created: / 26-05-2019 / 09:45:19 / Claus Gittinger"
24781
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   936
!
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   937
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   938
negative
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   939
    ^ timeEncoding < 0
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   940
!
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   941
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   942
positive
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
   943
    ^ timeEncoding >= 0
24159
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   944
! !
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
   945
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   946
!TimeDuration methodsFor:'converting'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   947
22862
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   948
asExactHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   949
    "answer the duration as hours.
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   950
     In contrast to asTruncatedHours, which returns them truncated,
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   951
     this may return a non-integer value."
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   952
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   953
    ^ self asExactSeconds / (3600)
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   954
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   955
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   956
     (2 hours + 10 minutes + 30 seconds) asExactHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   957
     (2 hours + 10 minutes + 30 seconds) asExactHours asFloat
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   958
     (2 hours + 10 minutes + 30 seconds) asTruncatedHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   959
     (2 hours + 10 minutes) asExactHours asFloat
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   960
     (2 hours + 10 minutes) asTruncatedHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   961
     10 milliseconds asExactHours 
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   962
     10 milliseconds asExactHours asFloat 
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   963
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   964
!
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
   965
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   966
asExactMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   967
    "return the exact number of mcroseconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   968
     In contrast to asMicroSeconds, which returns them truncated,
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   969
     this may return a non-integer value."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   970
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   971
    additionalPicoseconds isNil ifTrue:[
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   972
        ^ (timeEncoding * 1000) "/ millis as micros
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   973
    ].
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   974
    ^ (timeEncoding * 1000)                    "/ millis as micros 
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   975
    + (additionalPicoseconds / (1000 * 1000))  "/ picos as microseconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   976
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   977
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   978
     40 milliseconds asExactMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   979
     40 microseconds asExactMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   980
     40 nanoseconds asExactMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   981
     40 picoseconds asExactMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   982
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   983
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   984
    "Created: / 21-09-2017 / 18:52:26 / cg"
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   985
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   986
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   987
asExactMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   988
    "return the exact number of milliseconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   989
     In contrast to asMilliSeconds, which returns them truncated,
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   990
     this may return a non-integer value."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   991
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   992
    additionalPicoseconds isNil ifTrue:[
23230
c3ceaec4f180 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22997
diff changeset
   993
        ^ timeEncoding "/ millis
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   994
    ].
23230
c3ceaec4f180 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22997
diff changeset
   995
    ^ timeEncoding                         "/ millis 
c3ceaec4f180 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22997
diff changeset
   996
      + (additionalPicoseconds / (1000 * 1000 * 1000))  "/ picos as milliseconds.
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   997
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   998
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
   999
     40 milliseconds asExactMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1000
     40 microseconds asExactMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1001
     40 nanoseconds asExactMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1002
     40 picoseconds asExactMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1003
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1004
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1005
    "Created: / 21-09-2017 / 18:52:26 / cg"
23230
c3ceaec4f180 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22997
diff changeset
  1006
    "Modified (format): / 24-07-2018 / 16:27:10 / Stefan Vogel"
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1007
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1008
22862
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1009
asExactMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1010
    "answer the duration as minutes.
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1011
     In contrast to asTruncatedMinutes, which returns them truncated,
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1012
     this may return a non-integer value."
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1013
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1014
    ^ self asExactSeconds / 60
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1015
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1016
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1017
     (2 hours + 10 minutes + 30 seconds) asExactMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1018
     (2 hours + 10 minutes + 30 seconds) asExactMinutes asFloat
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1019
     (2 hours + 10 minutes + 30 seconds) asTruncatedMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1020
     (2 hours + 10 minutes) asExactMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1021
     (2 hours + 10 minutes) asTruncatedMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1022
     10 milliseconds asExactMinutes 
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1023
     10 milliseconds asExactMinutes asFloat 
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1024
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1025
!
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1026
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1027
asExactNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1028
    "return the exact number of nanoseconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1029
     In contrast to asNanoSeconds, which returns them truncated,
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1030
     this may return a non-integer value."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1031
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1032
    additionalPicoseconds isNil ifTrue:[
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1033
        ^ (timeEncoding * 1000 * 1000) "/ millis as nanos
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1034
    ].
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1035
    ^ (timeEncoding * 1000 * 1000)          "/ millis as nanos 
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1036
    + (additionalPicoseconds / (1000))      "/ picos as nanoseconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1037
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1038
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1039
     40 milliseconds asExactNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1040
     40 microseconds asExactNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1041
     40 nanoseconds asExactNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1042
     40 picoseconds asExactNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1043
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1044
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1045
    "Created: / 21-09-2017 / 18:52:26 / cg"
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1046
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1047
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1048
asExactSeconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1049
    "return the exact number of seconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1050
     In contrast to asSeconds, which returns them truncated,
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1051
     this may return a non-integer value."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1052
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1053
    additionalPicoseconds isNil ifTrue:[
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1054
        ^ (timeEncoding / 1000) "/ millis as seconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1055
    ].
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1056
    ^ (timeEncoding / 1000)                         "/ millis as seconds
22861
7764618c5649 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22860
diff changeset
  1057
    + (additionalPicoseconds / (1000 * 1000 * 1000 * 1000))  "/ picos as seconds.
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1058
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1059
    "
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1060
     1.5 milliSeconds asExactSeconds    
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1061
     1.5 seconds asExactSeconds    
22861
7764618c5649 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22860
diff changeset
  1062
     40 seconds asExactSeconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1063
     40 milliseconds asExactSeconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1064
     40 microseconds asExactSeconds
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1065
     40 nanoseconds asExactSeconds 
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1066
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1067
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1068
    "Created: / 21-09-2017 / 18:52:26 / cg"
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1069
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1070
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1071
asFixedPoint
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1072
    <resource: #obsolete>
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1073
    "answer the duration in seconds as a fixedPoint number.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1074
     This method has a bad name (a historic leftover);
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1075
     Please change any sender to use secondsAsFixedPoint"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1076
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1077
    ^ self secondsAsFixedPoint 
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1078
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1079
    "
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1080
     (10 milliseconds) asFixedPoint
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1081
     (10 milliseconds) asFixedPoint asFixedPoint:3 
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1082
    "
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1083
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1084
    "Modified (comment): / 14-09-2017 / 15:15:24 / stefan"
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1085
!
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1086
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1087
asFixedPoint:scale
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1088
    <resource: #obsolete>
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1089
    "answer the duration in seconds as a fixedPoint number with given scale.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1090
     This method has a bad name (a historic leftover);
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1091
     Please change any sender to use secondsAsFixedPoint"
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1092
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1093
    ^ self secondsAsFixedPoint:scale
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1094
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1095
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1096
     (1000 milliseconds) secondsAsFixedPoint
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1097
     (10 milliseconds) secondsAsFixedPoint
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1098
     (10 microseconds) secondsAsFixedPoint scale:8
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1099
     (10 nanoseconds) secondsAsFixedPoint scale:8   
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1100
     (1000001 microseconds) secondsAsFixedPoint scale:8
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1101
    "
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1102
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1103
    "Modified (comment): / 14-09-2017 / 15:15:24 / stefan"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1104
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1105
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1106
asFloat
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1107
    <resource: #obsolete>
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1108
    "answer the duration in seconds as a float.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1109
     This method has a bad name (a historic leftover);
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1110
     Please change any sender to use secondsAsFloat"
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1111
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1112
    ^ self secondsAsFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1113
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1114
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1115
     (1000 milliseconds) asFloat
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1116
     (10 milliseconds) asFloat
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1117
     (10 microseconds) asFloat
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1118
     (10 nanoseconds) asFloat
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1119
     (1000001 microseconds) asFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1120
    "
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1121
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1122
    "Modified (comment): / 14-09-2017 / 15:15:18 / stefan"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1123
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1124
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1125
asFraction
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1126
    <resource: #obsolete>
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1127
    "answer the duration in seconds as a fraction
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1128
     (might return an integer, if the duration is an exact multiple
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1129
      of millis).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1130
     This method has a bad name (a historic leftover);
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1131
     Please change any sender to use secondsAsFraction"
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1132
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1133
    ^ self secondsAsFraction
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1134
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1135
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1136
     (1000 milliseconds) asFraction
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1137
     (10 milliseconds) asFraction
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1138
     (10 microseconds) asFraction
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1139
     (10 nanoseconds) asFraction
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1140
     (1000001 microseconds) asFraction asFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1141
    "
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1142
22493
0232ebe18eb8 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22286
diff changeset
  1143
    "Modified (comment): / 19-01-2018 / 17:29:24 / stefan"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1144
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1145
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1146
asInteger
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1147
    <resource: #obsolete>
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1148
    "answer the duration as (truncated) integer seconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1149
     Better use the explicit asTruncatedSeconds"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1150
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1151
    ^ self asTruncatedSeconds
21506
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
  1152
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
  1153
    "
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1154
     10 milliseconds asInteger
21506
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
  1155
    "
32dccde0a4b9 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21446
diff changeset
  1156
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1157
    "Modified (comment): / 14-09-2017 / 15:14:49 / stefan"
22285
196d6c806fae #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22284
diff changeset
  1158
    "Modified (comment): / 21-09-2017 / 18:57:43 / cg"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1159
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1160
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1161
asLongFloat
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1162
    <resource: #obsolete>
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  1163
    "answer the duration as longfloat seconds.
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1164
     This method has a bad name (a historic leftover);
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1165
     Please change any sender to use secondsAsFloat"
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1166
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1167
    ^ self secondsAsLongFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1168
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1169
    "
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1170
     (10 milliseconds) asLongFloat
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1171
     (10 microseconds) asLongFloat
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1172
     (10 nanoseconds) asLongFloat
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1173
     (1000001 microseconds) asLongFloat
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1174
    "
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1175
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1176
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1177
asMicroseconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1178
    "answer the duration as microseconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1179
     Values smaller than 1 us will be returned as 0"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1180
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1181
    ^ self asTruncatedMicroseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1182
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1183
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1184
     100 nanoseconds asTruncatedMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1185
     100 nanoseconds asExactMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1186
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1187
     10 milliseconds asMicroseconds
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1188
     1.5 milliseconds asMicroseconds
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1189
     10 seconds asMicroseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1190
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1191
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1192
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1193
asMilliseconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1194
    "answer the duration as milliseconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1195
     Values smaller than 1 ms will be returned as 0"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1196
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1197
    ^ self asTruncatedMilliseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1198
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1199
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1200
     10 microseconds asTruncatedMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1201
     10 microseconds asExactMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1202
     10 microseconds asMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1203
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1204
     10 milliseconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1205
     10 seconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1206
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1207
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1208
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1209
asNanoseconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1210
    "answer the duration as nanoseconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1211
     Values smaller than 1 ns will be returned as 0"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1212
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1213
    ^ self asTruncatedNanoseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1214
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1215
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1216
     10 picoseconds asTruncatedNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1217
     10 picoseconds asExactNanoseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1218
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1219
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1220
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1221
asNumber
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1222
    <resource: #obsolete>
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1223
    "answer the duration as seconds.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1224
     This method has a bad name (a historic leftover);
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1225
     Please change any sender to use asTruncatedSeconds or
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1226
     asExactSeconds, depending on what is wanted."
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1227
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1228
    ^ self asExactSeconds
22255
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1229
4f96d547b1ca #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 22037
diff changeset
  1230
    "Modified (comment): / 14-09-2017 / 15:15:00 / stefan"
22285
196d6c806fae #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22284
diff changeset
  1231
    "Modified: / 21-09-2017 / 18:57:57 / cg"
16478
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1232
!
d2938d9d8d25 class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16462
diff changeset
  1233
22858
7b475b237f26 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22857
diff changeset
  1234
asPicoseconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1235
    "answer the duration as picoseconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1236
     Because the smallest representable timeDuration is 1ps,
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1237
     there is no distinction between truncated and exact picos."
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1238
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1239
    ^ (timeEncoding * 1000000000) + ((additionalPicoseconds ? 0))
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1240
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1241
    "
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1242
     10 milliseconds asPicoeconds
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1243
     10 seconds asPicoeconds
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1244
    "
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1245
!
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  1246
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1247
asSeconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1248
    "answer the duration as seconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1249
     Values smaller than 1 s will be returned as 0.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1250
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1251
     To get the exact number, use asExactSeconds.
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1252
     Please change senders to use asTruncatedSeconds 
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1253
     to make this truncation explicit (and obvious when reading code).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1254
     For compatibility (both backward and with other smalltalks),
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1255
     asSeconds returns the TRUNCATED integer value
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1256
     (many senders assume that an integer is returned)"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1257
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1258
    ^ self asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1259
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1260
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1261
     10 milliseconds asSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1262
     10 nanoseconds asSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1263
     10 milliseconds asExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1264
     10 nanoseconds asExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1265
     2 minutes asSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1266
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1267
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1268
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1269
asTimeDuration
20430
8ebafa5313a1 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19930
diff changeset
  1270
    "return a TimeDuration object from the receiver - that's the receiver."
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1271
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1272
    ^ self
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1273
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1274
22862
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1275
asTruncatedHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1276
    "answer the duration as hours (truncated).
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1277
     Values smaller than 1 h will be returned as 0.
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1278
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1279
     To get the exact number, use asExactHours."
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1280
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1281
    ^ self asTruncatedSeconds // (3600)
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1282
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1283
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1284
     (2 hours + 10 minutes) asTruncatedHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1285
     (2 hours + 10 minutes + 30 seconds) asTruncatedHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1286
     2 minutes asTruncatedHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1287
     10 milliseconds asTruncatedHours
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1288
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1289
!
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1290
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1291
asTruncatedMicroseconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1292
    "answer the duration as microseconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1293
     Values smaller than 1 us will be returned as 0.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1294
     This is the total number of microseconds - not just the fractional part"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1295
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1296
    ^ (timeEncoding * 1000) + ((additionalPicoseconds ? 0) // (1000 * 1000))
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1297
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1298
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1299
     100 nanoseconds asTruncatedMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1300
     100 nanoseconds asExactMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1301
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1302
     10 milliseconds asTruncatedMicroseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1303
     10 seconds asTruncatedMicroseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1304
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1305
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1306
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1307
asTruncatedMilliseconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1308
    "answer the duration as milliseconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1309
     Values smaller than 1 ms will be returned as 0.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1310
     This is the total number of milliseconds - not just the fractional part"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1311
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1312
    ^ timeEncoding
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1313
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1314
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1315
     0.1 milliseconds asTruncatedMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1316
     0.1 milliseconds asExactMilliseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1317
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1318
     10 milliseconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1319
     10 seconds asMilliseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1320
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1321
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1322
22862
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1323
asTruncatedMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1324
    "answer the duration as minutes (truncated).
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1325
     Values smaller than 1 m will be returned as 0.
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1326
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1327
     To get the exact number, use asExactMinutes."
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1328
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1329
    ^ self asTruncatedSeconds // 60
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1330
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1331
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1332
     (2 hours + 10 minutes) asTruncatedMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1333
     (2 hours + 10 minutes + 30 seconds) asTruncatedMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1334
     2 minutes asTruncatedMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1335
     10 milliseconds asTruncatedMinutes
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1336
    "
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1337
!
8139ede8f0cb #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22861
diff changeset
  1338
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1339
asTruncatedNanoseconds
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1340
    "answer the duration as nanoseconds (truncated).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1341
     Values smaller than 1 ns will be returned as 0.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1342
     This is the total number of nanoseconds - not just the fractional part"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1343
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1344
    ^ (timeEncoding * 1000000) + ((additionalPicoseconds ? 0) // (1000))
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1345
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1346
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1347
     10 picoseconds asTruncatedNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1348
     10 picoseconds asExactNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1349
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1350
     10 milliseconds asTruncatedNanoseconds
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1351
     10 seconds asTruncatedNanoseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1352
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1353
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1354
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1355
asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1356
    "answer the duration as seconds (truncated).
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1357
     Values smaller than 1 s will be returned as 0.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1358
     This is the total number of seconds - not just the fractional part.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1359
     To get the exact number, use asExactSeconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1360
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1361
    ^ timeEncoding // 1000
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1362
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1363
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1364
     10 milliseconds asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1365
     10 milliseconds asExactSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1366
     2 minutes asTruncatedSeconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  1367
    "
22860
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1368
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1369
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1370
secondsAsFixedPoint
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1371
    "answer the duration in seconds as a fixedPoint number."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1372
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1373
    ^ self secondsAsFixedPoint:4 
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1374
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1375
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1376
     (10 milliseconds) secondsAsFixedPoint
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1377
     (10 milliseconds) secondsAsFixedPoint asFixedPoint:3 
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1378
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1379
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1380
    "Modified (comment): / 14-09-2017 / 15:15:24 / stefan"
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1381
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1382
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1383
secondsAsFixedPoint:scale
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1384
    "answer the duration in seconds as a fixedPoint number with given scale."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1385
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1386
    |t|
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1387
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1388
    t := FixedPoint numerator:timeEncoding denominator:1000 scale:scale.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1389
    additionalPicoseconds notNil ifTrue:[
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1390
        t := t + (FixedPoint numerator:additionalPicoseconds denominator:((1000*1000)*(1000*1000)) scale:scale)
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1391
    ].
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1392
    ^ t
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1393
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1394
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1395
     (1000 milliseconds) secondsAsFixedPoint
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1396
     (10 milliseconds) secondsAsFixedPoint
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1397
     (10 microseconds) secondsAsFixedPoint scale:8
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1398
     (10 nanoseconds) secondsAsFixedPoint scale:8   
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1399
     (1000001 microseconds) secondsAsFixedPoint scale:8
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1400
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1401
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1402
    "Modified (comment): / 14-09-2017 / 15:15:24 / stefan"
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1403
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1404
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1405
secondsAsFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1406
    "answer the duration in seconds as a float."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1407
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1408
    |t|
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1409
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1410
    t := timeEncoding / 1000.0.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1411
    additionalPicoseconds notNil ifTrue:[
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1412
        t := t + (additionalPicoseconds / ((1000.0*1000.0) * (1000.0*1000.0))).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1413
    ].
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1414
    ^ t
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1415
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1416
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1417
     (1000 milliseconds) secondsAsFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1418
     (10 milliseconds) secondsAsFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1419
     (10 microseconds) secondsAsFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1420
     (10 nanoseconds) secondsAsFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1421
     (1000001 microseconds) secondsAsFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1422
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1423
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1424
    "Modified (comment): / 14-09-2017 / 15:15:18 / stefan"
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1425
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1426
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1427
secondsAsFraction
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1428
    "answer the duration in seconds as a fraction
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1429
     (might return an integer, if the duration is an exact multiple
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1430
      of millis)."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1431
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1432
    |t|
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1433
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1434
    t := timeEncoding / 1000.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1435
    additionalPicoseconds notNil ifTrue:[
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1436
        t := t + (additionalPicoseconds / ((1000*1000)*(1000*1000))).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1437
    ].
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1438
    ^ t
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1439
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1440
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1441
     (1000 milliseconds) secondsAsFraction
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1442
     (10 milliseconds) secondsAsFraction
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1443
     (10 microseconds) secondsAsFraction
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1444
     (10 nanoseconds) secondsAsFraction
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1445
     (1000001 microseconds) secondsAsFraction asFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1446
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1447
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1448
    "Modified (comment): / 19-01-2018 / 17:29:24 / stefan"
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1449
!
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1450
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1451
secondsAsLongFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1452
    "answer the duration as longfloat seconds."
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1453
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1454
    |t|
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1455
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1456
    t := timeEncoding / 1000 asLongFloat.
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1457
    additionalPicoseconds notNil ifTrue:[
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1458
        t := t + (additionalPicoseconds / (((1000*1000) asLongFloat) * (1000*1000) asLongFloat)).
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1459
    ].
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1460
    ^ t
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1461
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1462
    "
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1463
     (10 milliseconds) secondsAsLongFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1464
     (10 microseconds) secondsAsLongFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1465
     (10 nanoseconds) secondsAsLongFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1466
     (1000001 microseconds) secondsAsLongFloat
5a2c1731a17b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 22858
diff changeset
  1467
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1468
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1469
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1470
!TimeDuration methodsFor:'double dispatching'!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1471
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1472
differenceFromInteger:anInteger
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1473
    "treat the integer as a number of seconds.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1474
     Might be questionable, but adding integers to timeDurations is also allowed,
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1475
     and addition is kommutative...
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1476
     ...maybe mixing should be forbidden."
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1477
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1478
    ^ (self species seconds:anInteger) - self
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1479
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1480
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1481
     10 seconds - 5 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1482
     10 - 5 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1483
     10 seconds - 5 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1484
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1485
     10 seconds * 2 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1486
     2 * 10 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1487
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1488
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1489
    "Created: / 16-09-2017 / 12:49:33 / cg"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1490
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1491
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1492
differenceFromTimeDuration:aTimeDuration
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1493
    "return a new timeDuration"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1494
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1495
    |newMillis newPicos|
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1496
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1497
    newMillis := aTimeDuration getMilliseconds - timeEncoding.
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1498
    newPicos := (aTimeDuration additionalPicoseconds) - (additionalPicoseconds ? 0).
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1499
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1500
    ^ aTimeDuration species basicNew
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1501
        setMilliseconds:newMillis additionalPicoseconds:newPicos
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1502
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1503
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1504
     (TimeDuration fromString:'1m') - (TimeDuration fromString:'10s') 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1505
     1 minutes - 10 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1506
     10 - 1 minutes
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1507
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1508
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1509
    "Created: / 25-07-2018 / 21:17:50 / Stefan Vogel"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1510
    "Modified: / 27-07-2018 / 10:32:53 / Stefan Vogel"
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1511
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1512
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1513
differenceFromTimestamp:aTimestamp
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1514
    "return the timestamp this timeDuration before aTimestamp"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1515
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1516
    |newMillis newPicos|
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1517
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1518
    newMillis := aTimestamp getMilliseconds - timeEncoding.
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1519
    newPicos := (aTimestamp additionalPicoseconds) - (additionalPicoseconds ? 0).
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1520
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1521
    ^ aTimestamp species basicNew
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1522
        setMilliseconds:newMillis additionalPicoseconds:newPicos.
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1523
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1524
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1525
     Timestamp now - 100 seconds
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1526
     Time now - 100 seconds
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1527
     Timestamp now - 100
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1528
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1529
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1530
    "Modified (comment): / 16-09-2017 / 12:51:38 / cg"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1531
    "Modified (format): / 27-07-2018 / 10:50:13 / Stefan Vogel"
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1532
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1533
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1534
productFromFloat:aFloat
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1535
    "sent when aFloat does not know how to multiply the receiver.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1536
     Return a new timeDuration"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1537
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1538
    ^ self productFromNumber:aFloat
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1539
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1540
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1541
     5.1 * (TimeDuration fromString:'10s') 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1542
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1543
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1544
    "Modified (comment): / 12-06-2017 / 20:51:38 / cg"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1545
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1546
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1547
productFromFraction:aFraction
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1548
    "sent when aFraction does not know how to multiply the receiver.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1549
     Return a new timeDuration"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1550
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1551
    ^ self productFromNumber:aFraction
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1552
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1553
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1554
     (TimeDuration fromString:'10s') * 5
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1555
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1556
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1557
    "Modified (comment): / 12-06-2017 / 20:51:25 / cg"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1558
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1559
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1560
productFromInteger:anInteger
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1561
    "sent when an integer does not know how to multiply the receiver"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1562
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1563
    ^ self productFromNumber:anInteger
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1564
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1565
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1566
     5 * (TimeDuration fromString:'10s') 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1567
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1568
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1569
    "Modified (comment): / 12-06-2017 / 20:50:56 / cg"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1570
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1571
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1572
productFromNumber:aNumber
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1573
    "sent when an integer does not know how to multiply the receiver.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1574
     Return a new timeDuration"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1575
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1576
    ^ self species basicNew 
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1577
        setMilliseconds:(timeEncoding * aNumber) additionalPicoseconds:(additionalPicoseconds ? 0) * aNumber.
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1578
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1579
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1580
     5.1 * (TimeDuration fromString:'10s') 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1581
     (TimeDuration fromString:'10s') * 5
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1582
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1583
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1584
    "Modified (comment): / 16-09-2017 / 12:52:16 / cg"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1585
    "Modified: / 27-07-2018 / 10:33:21 / Stefan Vogel"
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1586
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1587
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1588
productFromTimeDuration:aTimeDuration
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1589
    "return a new timeDuration"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1590
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1591
    |t newMillis newPicos|
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1592
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1593
    (t := Smalltalk at:#'Physic::Time') notNil ifTrue:[
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1594
        ^ t dispatchProductFromAmount:(aTimeDuration asExactSeconds) 
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1595
            into:t 
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1596
            value:self asExactSeconds
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1597
    ].
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1598
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1599
    "/ the code below is completely bogus.
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1600
    "/ a square-second is NOT a second!!
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1601
    newMillis := timeEncoding * aTimeDuration getMilliseconds.
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1602
    newPicos := (additionalPicoseconds ? 0) * (aTimeDuration additionalPicoseconds).
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1603
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1604
    ^ aTimeDuration species basicNew
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1605
        setMilliseconds:newMillis additionalPicoseconds:newPicos
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1606
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1607
    "
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1608
     1 minutes * 10 seconds 
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1609
     10 * 1 minutes         
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1610
     1 minutes * 5        
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1611
     (TimeDuration fromString:'10s') * (TimeDuration fromString:'10s')  
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  1612
     (TimeDuration fromString:'10s') / (TimeDuration fromString:'10s')  
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1613
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1614
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1615
    "Created: / 25-07-2018 / 21:11:40 / Stefan Vogel"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1616
    "Modified: / 27-07-2018 / 10:33:29 / Stefan Vogel"
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1617
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1618
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1619
sumFromInteger:anInteger
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1620
    "treat the integer as a number of seconds.
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1621
     Might be questionable, but adding integers to timeDurations is also allowed,
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1622
     and addition is kommutative...
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1623
     ...maybe mixing should be forbidden."
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1624
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1625
    ^ self addSeconds:anInteger
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1626
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1627
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1628
     10 + 5 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1629
     10 seconds + 5 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1630
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1631
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1632
    "Created: / 16-09-2017 / 12:46:20 / cg"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1633
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1634
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1635
sumFromTimeDuration:aTimeDuration
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1636
    "return a new timeDuration"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1637
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1638
    |newMillis newPicos|
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1639
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1640
    newMillis := timeEncoding + aTimeDuration getMilliseconds.
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1641
    newPicos := (additionalPicoseconds ? 0) + (aTimeDuration additionalPicoseconds).
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1642
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1643
    ^ aTimeDuration species basicNew
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1644
        setMilliseconds:newMillis additionalPicoseconds:newPicos
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1645
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1646
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1647
     (TimeDuration fromString:'1m') + (TimeDuration fromString:'10s') 
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1648
     1 minutes + 10 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1649
     10 + 1 minutes
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1650
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1651
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1652
    "Created: / 16-09-2017 / 12:43:28 / cg"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1653
    "Modified: / 27-07-2018 / 10:33:47 / Stefan Vogel"
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1654
!
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1655
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1656
sumFromTimestamp:aTimestamp
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1657
    "return the timestamp this timeDuration after aTimestamp"
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1658
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1659
    |newMillis newPicos|
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1660
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1661
    newMillis := timeEncoding + aTimestamp getMilliseconds.
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1662
    newPicos := (additionalPicoseconds ? 0) + (aTimestamp additionalPicoseconds).
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1663
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1664
    ^ aTimestamp species basicNew
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1665
        setMilliseconds:newMillis additionalPicoseconds:newPicos
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1666
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1667
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1668
     Timestamp now + 100 seconds
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1669
    "
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1670
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1671
    "Modified (comment): / 16-09-2017 / 12:53:14 / cg"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  1672
    "Modified: / 27-07-2018 / 10:30:13 / Stefan Vogel"
23233
0070f1889bc6 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23230
diff changeset
  1673
! !
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1674
24159
f3f05b723a29 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24113
diff changeset
  1675
24781
0d393e57e171 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 24523
diff changeset
  1676
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1677
!TimeDuration methodsFor:'printing'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1678
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1679
addPrintBindingsTo:aDictionary language:languageOrNil
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1680
    "private print support: add bindings for printing to aDictionary.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1681
     languageOrNil can only be #en or nil for the current language.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1682
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1683
     Additional formats available here (for timeDuration) are:
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1684
        %(Hd)       hours in day (i.e. 0..23)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1685
        %(hd)       hours in day padded to 2 chars (i.e. 00..23)
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1686
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1687
        %(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
  1688
        %(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
  1689
        %(w)        weeks 
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1690
        %(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
  1691
        %(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
  1692
        %(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
  1693
        %(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
  1694
        %(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
  1695
        %(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
  1696
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1697
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1698
    |hoursInDay s yearsRounded monthsRounded weeksRounded daysRounded hoursRounded minutesRounded secondsRounded|
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1699
16830
1d5965daab9a class: TimeDuration
Stefan Vogel <sv@exept.de>
parents: 16506
diff changeset
  1700
    self addBasicPrintBindingsTo:aDictionary language:languageOrNil.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1701
    aDictionary at:$d put:self days.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1702
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1703
    hoursInDay := self hours \\ 24.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1704
    aDictionary at:#Hd put:(s := hoursInDay printString).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1705
    aDictionary at:#hd put:(s leftPaddedTo:2 with:$0).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1706
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1707
    aDictionary at:#dw put:(self days \\ 7).
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1708
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1709
    yearsRounded := (self hours / 24 / 365).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1710
    yearsRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1711
        yearsRounded := yearsRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1712
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1713
    aDictionary at:#yrR put:yearsRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1714
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1715
    monthsRounded := self days / 30.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1716
    monthsRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1717
        monthsRounded := monthsRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1718
        monthsRounded roundedToScale = monthsRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1719
            monthsRounded := monthsRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1720
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1721
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1722
    aDictionary at:#monR put:monthsRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1723
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1724
    aDictionary at:#w put:(self days // 7).
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1725
    weeksRounded := self days / 7.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1726
    weeksRounded isInteger ifFalse:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1727
        weeksRounded := weeksRounded asFixedPoint:1.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1728
        weeksRounded roundedToScale = weeksRounded asInteger ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1729
            weeksRounded := weeksRounded truncated
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1730
        ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1731
    ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1732
    aDictionary at:#wR put:weeksRounded.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1733
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1734
    daysRounded := (self hours / 24).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1735
    daysRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1736
        daysRounded := daysRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1737
        daysRounded roundedToScale = daysRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1738
            daysRounded := daysRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1739
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1740
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1741
    aDictionary at:#dR put:daysRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1742
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1743
    hoursRounded := self hours + (self minutes / 60).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1744
    hoursRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1745
        hoursRounded := hoursRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1746
        hoursRounded roundedToScale = hoursRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1747
            hoursRounded := hoursRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1748
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1749
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1750
    aDictionary at:#hR put:hoursRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1751
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1752
    minutesRounded := self minutes + (self seconds / 60).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1753
    minutesRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1754
        minutesRounded := minutesRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1755
        minutesRounded roundedToScale = minutesRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1756
            minutesRounded := minutesRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1757
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1758
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1759
    aDictionary at:#mR put:minutesRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1760
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1761
    secondsRounded := self seconds + (self milliseconds / 1000).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1762
    secondsRounded isInteger ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1763
        secondsRounded := secondsRounded asFixedPoint:1.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1764
        secondsRounded roundedToScale = secondsRounded asInteger ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1765
            secondsRounded := secondsRounded truncated
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1766
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1767
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1768
    aDictionary at:#sR put:secondsRounded.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1769
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1770
    "Modified: / 22-02-2011 / 15:55:38 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1771
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1772
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1773
formatForApproximatePrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1774
    "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
  1775
     In contrast to the regular format, this one only gives a rounded approximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1776
     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
  1777
     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
  1778
     individual seconds or even milliseconds.
24523
758ae1a35ecb #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 24365
diff changeset
  1779
     The way this is done is pure magic heuristics - let me know, if you have a better algorithm."
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1780
22930
8a5a2399ea28 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22918
diff changeset
  1781
    |hours mins secs millis|
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1782
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1783
    hours := self hours.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1784
22286
b67c6cd14b84 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22285
diff changeset
  1785
    hours >= (24*365*2) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1786
        ^ '%(yrR)yr'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1787
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1788
    hours >= (24*40) ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1789
        ^ '%(monR)mon'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1790
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1791
    hours >= 48 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1792
        ^ '%(dR)d'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1793
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1794
    hours >= 24 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1795
        ^ '%dd %(Hd)h'. 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1796
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1797
    hours >= 2 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1798
        ^ '%(hR)h'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1799
    ].
24890
7453e1747201 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24808
diff changeset
  1800
    hours > 0 ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1801
        ^ '%Hh %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1802
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1803
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1804
    "/ no hours
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1805
    mins := self minutes.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1806
    mins >= 5 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1807
        ^ '%(mR)m'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1808
    ].
24890
7453e1747201 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24808
diff changeset
  1809
    mins > 0 ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1810
        ^ '%Mm %Ss'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1811
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1812
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1813
    "/ no mins
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1814
    secs := self seconds.
24890
7453e1747201 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 24808
diff changeset
  1815
    secs > 0 ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1816
        secs >= 30 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1817
            ^ '%(S)s'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1818
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1819
        ^ '%(sR)s'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1820
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1821
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1822
    "/ no secs
22930
8a5a2399ea28 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22918
diff changeset
  1823
    millis := self milliseconds.
8a5a2399ea28 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22918
diff changeset
  1824
    millis > 500 ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1825
        ^ '%(sR)s'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1826
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1827
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1828
    ^ self formatForPrinting
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 hours:0 minutes:0 seconds:0 millis:12) printStringForApproximation       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1832
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1833
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1834
     (TimeDuration hours:0 minutes:1 seconds:10 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1835
     (TimeDuration hours:0 minutes:2 seconds:10 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1836
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1837
     (TimeDuration hours:2 minutes:0 seconds:0 millis:123) printStringForApproximation         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1838
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringForApproximation        
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1839
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringForApproximation      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1840
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringForApproximation    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1841
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringForApproximation    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1842
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1843
     (TimeDuration hours:2 minutes:33 seconds:0 millis:0) printStringForApproximation         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1844
     (TimeDuration hours:2 minutes:0 seconds:0 millis:0) printStringForApproximation          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1845
     (TimeDuration hours:24 minutes:0 seconds:0 millis:0) printStringForApproximation          
22930
8a5a2399ea28 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22918
diff changeset
  1846
8a5a2399ea28 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22918
diff changeset
  1847
     (TimeDuration fromMicroseconds:20) printStringForApproximation          
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1848
    "
22286
b67c6cd14b84 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22285
diff changeset
  1849
b67c6cd14b84 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22285
diff changeset
  1850
    "Modified: / 21-09-2017 / 22:19:53 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1851
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1852
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1853
formatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1854
    "Return the format for printing"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1855
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1856
    DefaultFormatForPrinting notNil ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1857
        ^ DefaultFormatForPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1858
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1859
    ^ self formatForPrinting:false
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1860
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1861
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1862
     (TimeDuration readFrom:'10h 3s') formatForPrinting  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1863
     (TimeDuration readFrom:'3s') formatForPrinting      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1864
     (TimeDuration readFrom:'1d 2ms') formatForPrinting      
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  1865
     (TimeDuration readFrom:'1 week') formatForPrinting      
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1866
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1867
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1868
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1869
formatForShortPrinting
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1870
    "Return the short format for printing (without ms)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1871
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1872
    ^ self formatForPrinting:true
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1873
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1874
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1875
printAsApproximationOn:aStream
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1876
    "append a human readable printed representation of the receiver to aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1877
     The format is meant for a human and does not give all information;
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1878
     especially, useless detail is hidden.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1879
     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
  1880
     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
  1881
     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
  1882
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1883
    ^ self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1884
        printOn:aStream 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1885
        format:(self formatForApproximatePrinting).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1886
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1887
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1888
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1889
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1890
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1891
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1892
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1893
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1894
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1895
     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1896
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1897
     (TimeDuration hours:2 minutes:33 seconds:0) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1898
     (TimeDuration hours:2 minutes:0 seconds:0) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1899
     (TimeDuration hours:24 minutes:0 seconds:0) printAsApproximationOn:Transcript
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1900
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1901
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1902
    "Modified: / 18-07-2007 / 14:06:17 / cg"
21446
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  1903
    "Modified (comment): / 13-02-2017 / 20:32:54 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1904
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1905
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1906
printOn:aStream
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1907
    "append a human readable printed representation of the receiver to aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1908
     The format is suitable for a human - not meant to be read back."
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1909
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1910
    timeEncoding negative ifTrue:[
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1911
        aStream nextPutAll:'-('.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1912
        (self class basicNew timeEncoding:timeEncoding negated) printOn:aStream.
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  1913
        aStream nextPutAll:')'.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1914
        ^  self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1915
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1916
    ^ self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1917
        printOn:aStream 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1918
        format:(self formatForPrinting).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1919
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1920
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1921
     TimeDuration hours:0 minutes:0 seconds:0 millis:12       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1922
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1923
     TimeDuration hours:0 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1924
     TimeDuration hours:0 minutes:0 seconds:10 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1925
     TimeDuration hours:0 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1926
     TimeDuration hours:2 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1927
     TimeDuration hours:2 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1928
     TimeDuration hours:100 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1929
     TimeDuration hours:10000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1930
     TimeDuration hours:1000000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1931
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1932
     TimeDuration hours:2 minutes:33 seconds:0 millis:0         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1933
     TimeDuration hours:2 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1934
     TimeDuration hours:24 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1935
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1936
     (TimeDuration hours:0 minutes:0 seconds:0 millis:123) printStringFormat:'%h:%m:%s'       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1937
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1938
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1939
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1940
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1941
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1942
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1943
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1944
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1945
    "Modified: / 18-07-2007 / 14:06:17 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1946
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1947
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1948
printShortOn:aStream
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1949
    "append a human readable printed representation  
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1950
     of the receiver to aStream (without milliseconds)"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1951
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1952
    ^ self
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1953
        printOn:aStream 
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1954
        format:(self formatForShortPrinting).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1955
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1956
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1957
     TimeDuration hours:0 minutes:0 seconds:0 millis:12       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1958
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1959
     TimeDuration hours:0 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1960
     TimeDuration hours:0 minutes:0 seconds:10 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1961
     TimeDuration hours:0 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1962
     TimeDuration hours:2 minutes:0 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1963
     TimeDuration hours:2 minutes:33 seconds:0 millis:123       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1964
     TimeDuration hours:100 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1965
     TimeDuration hours:10000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1966
     TimeDuration hours:1000000 minutes:33 seconds:0 millis:123    
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1967
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1968
     TimeDuration hours:2 minutes:33 seconds:0 millis:0         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1969
     TimeDuration hours:2 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1970
     TimeDuration hours:24 minutes:0 seconds:0 millis:0          
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1971
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1972
     (TimeDuration hours:0 minutes:0 seconds:0 millis:123) printStringFormat:'%h:%m:%s'       
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1973
     (TimeDuration hours:0 minutes:0 seconds:10 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1974
     (TimeDuration hours:0 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1975
     (TimeDuration hours:2 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'         
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1976
     (TimeDuration hours:100 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1977
     (TimeDuration hours:10000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1978
     (TimeDuration hours:1000000 minutes:33 seconds:0 millis:123) printStringFormat:'%h:%m:%s'      
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1979
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1980
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1981
    "Modified: / 18-07-2007 / 14:06:17 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1982
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1983
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1984
printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1985
    "return a human readable printed representation of the receiver to aStream.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1986
     The format is meant for a human and does not give all information;
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1987
     especially, useless detail is hidden.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1988
     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
  1989
     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
  1990
     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
  1991
20837
3e0095bef7e6 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 20704
diff changeset
  1992
    ^ self printStringFormat:(self formatForApproximatePrinting).
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1993
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1994
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1995
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1996
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1997
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1998
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1999
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2000
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2001
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2002
     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2003
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2004
     (TimeDuration hours:2 minutes:33 seconds:0) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2005
     (TimeDuration hours:2 minutes:0 seconds:0) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2006
     (TimeDuration hours:24 minutes:0 seconds:0) printStringForApproximation
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2007
    "
21446
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  2008
c4de48f134d1 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 20837
diff changeset
  2009
    "Modified (comment): / 13-02-2017 / 20:32:59 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2010
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2011
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2012
!TimeDuration methodsFor:'private'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2013
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2014
additionalPicoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2015
    "get the optional additional picoseconds (0..999999999)
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2016
     notice: that is NOT the total number of picoseconds,
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2017
     but the fractional part only. 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2018
     Use this only for printing."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2019
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2020
    ^ additionalPicoseconds ? 0
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2021
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2022
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2023
additionalPicoseconds:picosecondPart
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2024
    "set the optional additional picoseconds (0..999999999)"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2025
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2026
    self assert:(picosecondPart isInteger).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2027
    self assert:(picosecondPart < (1000*1000*1000)).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2028
    additionalPicoseconds := picosecondPart
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2029
!
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2030
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2031
formatForPrinting:shortFlag
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2032
    "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
  2033
     (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
  2034
      but instead round it heuristically.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2035
     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
  2036
     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
  2037
     For timeDurations to be read back exactly, use iso8601 format."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2038
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2039
    |fmt days weeks hours mins secs 
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2040
     overAllSeconds overAllMicros overAllNanos millis|
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2041
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2042
    days := self days.  "/ that's the total
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2043
    weeks := days // 7.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2044
    hours := self hours.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2045
    mins := self minutes.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2046
    secs := self seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2047
    millis := self milliseconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2048
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2049
    "/ 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
  2050
    weeks > 0 ifTrue:[
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2051
        "/ 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
  2052
        fmt := '%(w)w %(dw)d %(Hd)h %Mm'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2053
        secs = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2054
            fmt := '%(w)w %(dw)d %(Hd)h %Mm'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2055
            mins = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2056
                fmt := '%(w)w %(dw)d %(Hd)h'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2057
                (hours \\ 24) = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2058
                    fmt := '%(w)w %(dw)d'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2059
                    (days \\ 7) = 0 ifTrue:[
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2060
                        fmt := '%(w)w'.
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2061
                    ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2062
                ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2063
            ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2064
        ].
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2065
    ] ifFalse:[days > 0 ifTrue:[
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2066
        "/ notice: d here, which prints the total number of days
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2067
        fmt := '%dd %(Hd)h %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2068
        secs = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2069
            fmt := '%dd %(Hd)h %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2070
            mins = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2071
                fmt := '%dd %(Hd)h'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2072
                (hours \\ 24) = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2073
                    fmt := '%dd'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2074
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2075
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2076
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2077
    ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2078
        hours > 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2079
            fmt := '%Hh %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2080
            secs = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2081
                fmt := '%Hh %Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2082
                mins = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2083
                    fmt := '%Hh'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2084
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2085
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2086
        ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2087
            mins > 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2088
                fmt := '%Mm'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2089
                secs = 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2090
                    fmt := '%Mm'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2091
                ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2092
            ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2093
                fmt := ''
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2094
            ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2095
        ].
19930
2d09029fec45 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 19849
diff changeset
  2096
    ]].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2097
    ((secs ~= 0) or:[millis ~= 0 or:[(additionalPicoseconds?0) ~= 0]]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2098
        fmt size ~~ 0 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2099
            fmt := fmt , ' '
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2100
        ].
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2101
        ((millis = 0) and:[(additionalPicoseconds?0) = 0]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2102
            fmt := fmt , '%Ss'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2103
        ] ifFalse:[
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2104
            (secs = 0 and:[(additionalPicoseconds?0) = 0]) ifTrue:[
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2105
                fmt := fmt , '%Ims'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2106
            ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2107
                shortFlag ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2108
                    "/ show millis
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2109
                    (millis ~= 0) ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2110
                        fmt := fmt , '%S.%is'
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2111
                    ] ifFalse:[
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  2112
                        overAllMicros := self microseconds.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2113
                        overAllMicros > 2 ifTrue:[
24893
373cc0ac5f71 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 24890
diff changeset
  2114
                            fmt := fmt , '%(micro)µs'.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2115
                        ] ifFalse:[
22857
d3675e380987 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22856
diff changeset
  2116
                            overAllNanos := self nanoseconds.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2117
                            overAllNanos > 2 ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2118
                                fmt := fmt , '%(nano)ns'.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2119
                            ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2120
                                fmt := fmt , '%(pico)ps'.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2121
                            ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2122
                        ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2123
                    ].
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2124
                ] ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2125
                    "/ only show millis if the number of seconds is small
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2126
                    overAllSeconds := self asSeconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2127
                    overAllSeconds > 2 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2128
                        overAllSeconds > 10 ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2129
                            overAllSeconds > 300 ifTrue:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  2130
                               "/ no decimal above 300 seconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2131
                                fmt := fmt , '%Ss'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2132
                            ] ifFalse:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  2133
                               "/ 1 decimals up to 300 seconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2134
                                fmt := fmt , '%S.%(milli1)s'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2135
                            ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2136
                        ] ifFalse:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  2137
                           "/ 2 decimals up to 10seconds
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2138
                            fmt := fmt , '%S.%(milli2)s'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2139
                        ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2140
                    ] ifFalse:[
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  2141
                        "/ millis up to 2seconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2142
                        fmt := fmt , '%S.%is'.
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2143
                    ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2144
                ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2145
            ]
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2146
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2147
    ] ifFalse:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2148
        fmt isEmpty ifTrue:[
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2149
            fmt := '%Ss'
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2150
        ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2151
    ].
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2152
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2153
    ^ fmt.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2154
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2155
    "
22817
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
  2156
     3001 seconds formatForPrinting:false
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
  2157
     3001 seconds formatForPrinting:true
65a92285bb30 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22652
diff changeset
  2158
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2159
     (TimeDuration fromString:'1w 3d') formatForPrinting
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2160
     (TimeDuration fromString:'1w 3d') printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2161
     (TimeDuration fromString:'7d') printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2162
     (TimeDuration fromString:'6d') printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2163
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2164
     (TimeDuration fromMilliseconds:0.5) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2165
     (TimeDuration fromMilliseconds:0.05) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2166
     (TimeDuration fromMilliseconds:0.005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2167
     (TimeDuration fromMilliseconds:0.0005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2168
     (TimeDuration fromMilliseconds:0.00005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2169
     (TimeDuration fromMilliseconds:0.000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2170
     (TimeDuration fromMilliseconds:0.0000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2171
     (TimeDuration fromMilliseconds:0.00000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2172
     (TimeDuration fromMilliseconds:0.000000005) printString
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2173
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2174
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:12) formatForPrinting
22519
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  2175
     (TimeDuration hours:0 minutes:0 seconds:2 milliseconds:12) formatForPrinting 
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  2176
     (TimeDuration hours:0 minutes:0 seconds:8 milliseconds:12) formatForPrinting  
040b32959a91 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22493
diff changeset
  2177
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:12) formatForPrinting  
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2178
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2179
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2180
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2181
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2182
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2183
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2184
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2185
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2186
     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) formatForPrinting
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2187
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2188
     (TimeDuration hours:0 minutes:38 seconds:22 milliseconds:123) formatForPrinting:true
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2189
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2190
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:0) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2191
     (TimeDuration hours:2 minutes:0 seconds:0 milliseconds:0) formatForPrinting
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2192
     (TimeDuration hours:24 minutes:0 seconds:0 milliseconds:0) formatForPrinting
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2193
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2194
     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2195
     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2196
     (TimeDuration hours:0 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2197
     (TimeDuration hours:2 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2198
     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2199
     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2200
     (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
  2201
    "
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2202
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2203
    "Modified: / 18-07-2007 / 14:06:17 / cg"
21757
337bf1ed4246 #OTHER by mawalch
mawalch
parents: 21697
diff changeset
  2204
    "Modified (comment): / 17-05-2017 / 16:35:56 / mawalch"
22997
1c2629bf2cac #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22990
diff changeset
  2205
    "Modified: / 23-05-2018 / 10:36:21 / Claus Gittinger"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2206
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2207
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2208
getHours
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2209
    "return the number of hours (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2210
     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
  2211
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2212
    ^ self getSeconds // 60 // 60
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2213
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2214
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2215
getMicroseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2216
    "return the number of microseconds (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2217
     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
  2218
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2219
    ^ (timeEncoding * 1000) + ((additionalPicoseconds ? 0) // (1000 * 1000))
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2220
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2221
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2222
getMilliseconds
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2223
    "return the number of milliseconds (truncated).
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  2224
     This is the total number of milliseconds - not just the fractional part"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2225
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2226
    ^ timeEncoding
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2227
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2228
    "Modified: / 18-07-2007 / 13:44:33 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2229
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2230
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2231
getMinutes
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2232
    "return the number of minutes (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2233
     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
  2234
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2235
    ^ self getSeconds // 60
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2236
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2237
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2238
getPicoseconds
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2239
    "return the number of picoseconds (truncated).
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2240
     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
  2241
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2242
    ^ (timeEncoding * 1000000000) + ((additionalPicoseconds ? 0))
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2243
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2244
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2245
getSeconds
22625
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  2246
    "return the number of seconds (truncated).
c329c0b27248 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22621
diff changeset
  2247
     This is the total number of seconds - not just the fractional part"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2248
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2249
    ^ timeEncoding // 1000
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2250
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2251
    "Modified: / 18-07-2007 / 13:44:37 / cg"
22281
e7b51a58d9b4 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22255
diff changeset
  2252
    "Modified (comment): / 21-09-2017 / 18:50:03 / cg"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2253
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2254
20704
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  2255
possiblyNegatedValueFromTimeEncodingInto:aBlock
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  2256
    timeEncoding < 0 ifTrue:[
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  2257
        ^ (aBlock value:(timeEncoding negated)) negated
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  2258
    ].    
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  2259
    ^ aBlock value:timeEncoding
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  2260
!
0f8d62be3318 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20430
diff changeset
  2261
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2262
setHours:h minutes:m seconds:s millis:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2263
    <resource: #obsolete>
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2264
    "set my time given individual values"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2265
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2266
    self obsoleteMethodWarning:'use setHours:minutes:seconds:milliseconds:'.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2267
    self setHours:h minutes:m seconds:s milliseconds:millis.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2268
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2269
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2270
setHours:h minutes:m seconds:s milliseconds:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2271
    "set my time given individual values"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2272
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2273
    self setMilliseconds:((h * 60 * 60 ) + (m * 60) + s) * 1000 + millis.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2274
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2275
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2276
setMicroseconds:micros
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2277
    "set my duration given microseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2278
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2279
    |restMicros|
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2280
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  2281
    timeEncoding := micros // 1000.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2282
    micros isInteger ifTrue:[
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2283
        additionalPicoseconds := (micros \\ 1000) * 1000000
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2284
    ] ifFalse:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2285
        restMicros := micros - (timeEncoding * 1000).
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2286
        additionalPicoseconds := (restMicros * 1000000) truncated.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2287
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2288
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2289
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2290
     self new setMicroseconds:100
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2291
     self new setMicroseconds:2
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2292
     self new setMicroseconds:1.5
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2293
     self new setMicroseconds:0.1
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2294
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2295
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2296
    "Modified: / 18-07-2007 / 13:44:16 / cg"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  2297
    "Modified: / 27-07-2018 / 11:53:05 / Stefan Vogel"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2298
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2299
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2300
setMilliseconds:millis
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2301
    "set my duration given milliseconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2302
     Duration can be longer than a day"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2303
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2304
    millis isInteger ifTrue:[
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2305
        timeEncoding := millis.
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2306
    ] ifFalse:[
22866
43f44339eee0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22865
diff changeset
  2307
        timeEncoding := millis // 1.
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2308
        additionalPicoseconds := ((millis \\ 1) * 1000000000) truncated.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2309
    ]
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2310
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2311
    "Modified: / 18-07-2007 / 13:44:16 / cg"
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2312
    "Modified: / 22-05-2018 / 16:51:30 / Stefan Vogel"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2313
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2314
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2315
setMilliseconds:millis additionalPicoseconds:picos
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2316
    "set my duration given milliseconds and addon picos.
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2317
     Duration can be longer than a day; 
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2318
     values may be negative (eg. if resulting from a subtraction)"
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2319
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2320
    |rest newMillis newPicos|
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2321
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2322
    millis isInteger ifTrue:[
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2323
        newMillis := millis.
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2324
        newPicos := 0.
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2325
    ] ifFalse:[
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2326
        newMillis := millis truncated.
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2327
        rest := millis - newMillis.
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2328
        newPicos := (rest * 1000000000) truncated.
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2329
    ].
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2330
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2331
    picos ~= 0 ifTrue:[
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2332
        newPicos := (newPicos + picos) truncated.
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2333
        newMillis := newMillis + (newPicos // 1000000000).
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2334
        newPicos := newPicos \\ 1000000000.
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2335
    ].
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2336
    timeEncoding := newMillis.
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2337
    additionalPicoseconds := newPicos.
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2338
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2339
    "Modified: / 18-07-2007 / 13:44:16 / cg"
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2340
    "Modified: / 22-05-2018 / 16:55:53 / Stefan Vogel"
22863
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2341
!
ea25b6e2cdae #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22862
diff changeset
  2342
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2343
setNanoseconds:nanos
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2344
    "set my duration given nanoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2345
22891
ac18d6513ef8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22887
diff changeset
  2346
    |millis restNanos|
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2347
22891
ac18d6513ef8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22887
diff changeset
  2348
    millis := nanos // (1000*1000).
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  2349
    timeEncoding := millis.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2350
    nanos isInteger ifTrue:[
22891
ac18d6513ef8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22887
diff changeset
  2351
        restNanos := nanos \\ (1000*1000).
ac18d6513ef8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22887
diff changeset
  2352
        additionalPicoseconds := restNanos * 1000 
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2353
    ] ifFalse:[
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2354
        restNanos := nanos - (millis * 1000000).
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2355
        additionalPicoseconds := (restNanos * 1000) truncated.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2356
    ].
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2357
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2358
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2359
     self new setMicroseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2360
     self new setNanoseconds:4
22891
ac18d6513ef8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22887
diff changeset
  2361
     self new setNanoseconds:4000
ac18d6513ef8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22887
diff changeset
  2362
     self new setNanoseconds:4000000
ac18d6513ef8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22887
diff changeset
  2363
     self new setNanoseconds:40000000
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2364
     self new setNanoseconds:0.1
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2365
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2366
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2367
    "Modified: / 18-07-2007 / 13:44:16 / cg"
23238
b6fdc6aabf3f #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23233
diff changeset
  2368
    "Modified: / 27-07-2018 / 11:53:41 / Stefan Vogel"
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2369
!
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2370
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2371
setPicoseconds:picos
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2372
    "set my duration given picoseconds."
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2373
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2374
    timeEncoding := picos // 1000000000.
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2375
    additionalPicoseconds := (picos \\ 1000000000) truncated.
22843
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2376
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2377
    "
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2378
     self new setMicroseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2379
     self new setNanoseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2380
     self new setPicoseconds:4
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2381
     self new setPicoseconds:4.5
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2382
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2383
     self assert: (self new setPicoseconds:4000) = (self new setNanoseconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2384
     self assert: (self new setPicoseconds:4000000) = (self new setNanoseconds:4000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2385
     self assert: (self new setPicoseconds:4000000) = (self new setMicroseconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2386
     self assert: (self new setPicoseconds:4000000000) = (self new setNanoseconds:4000000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2387
     self assert: (self new setPicoseconds:4000000000) = (self new setMicroseconds:4000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2388
     self assert: (self new setPicoseconds:4000000000) = (self new setMilliseconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2389
     self assert: (self new setPicoseconds:4000000000000) = (self new setMilliseconds:4000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2390
     self assert: (self new setPicoseconds:4000000000000) = (self new setMicroseconds:4000000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2391
     self assert: (self new setPicoseconds:4000000000000) = (self new setNanoseconds:4000000000) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2392
     self assert: (self new setPicoseconds:4000000000000) = (self new setSeconds:4) .
d6201034cacd #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22817
diff changeset
  2393
    "
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2394
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2395
    "Modified: / 18-07-2007 / 13:44:16 / cg"
22990
4efa84e493a9 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22930
diff changeset
  2396
    "Modified: / 22-05-2018 / 16:51:45 / Stefan Vogel"
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2397
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2398
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2399
setSeconds:secs
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2400
    "set my timeduration given seconds.
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2401
     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
  2402
     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
  2403
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2404
    self setMilliseconds:(secs * 1000).
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2405
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2406
    "Modified: / 18-07-2007 / 13:44:24 / cg"
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2407
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2408
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2409
!TimeDuration methodsFor:'testing'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2410
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2411
isTimeDuration
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2412
    ^ true
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2413
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2414
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2415
isZero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2416
    ^ self = self class zero
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2417
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2418
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2419
!TimeDuration class methodsFor:'documentation'!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2420
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2421
version
18564
55bd2aa4d56e class: TimeDuration
Claus Gittinger <cg@exept.de>
parents: 17388
diff changeset
  2422
    ^ '$Header$'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2423
!
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2424
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2425
version_CVS
18564
55bd2aa4d56e class: TimeDuration
Claus Gittinger <cg@exept.de>
parents: 17388
diff changeset
  2426
    ^ '$Header$'
16356
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2427
! !
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2428
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2429
d9c6b891d04c class: TimeDuration
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2430
TimeDuration initialize!