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