--- a/TimeDuration.st Fri Jun 03 14:16:11 2016 +0200
+++ b/TimeDuration.st Fri Jun 03 16:16:21 2016 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -685,15 +687,18 @@
%(Hd) hours in day (i.e. 0..23)
%(hd) hours in day padded to 2 chars (i.e. 00..23)
- %(yrR) years rounded (i.e. for 730 days, we get 2 asFixed:1 )
- %(monR) month rounded (i.e. for 45 days, we get 1.5 asFixed:1 )
- %(dR) days rounded (i.e. for 36 hours, we get 1.5 asFixed:1 )
- %(hR) hours rounded (i.e. for 3h 30m, we get 3.5 asFixed:1 )
- %(mR) minutes rounded (i.e. for 2m 30s, we get 2.5 asFixed:1 )
- %(sR) seconds rounded to 1 postDecimal (i.e. for 2s 100ms, we get 2.1 asFixed:1 )
+ %(yrR) years rounded (i.e. for 730 days, we get 2 asFixedPoint:1 )
+ %(monR) month rounded (i.e. for 45 days, we get 1.5 asFixedPoint:1 )
+ %(w) weeks
+ %(wR) weeks rounded (i.e. for 45 days, we get 6.xxx asFixedPoint:1 )
+ %(dR) days rounded (i.e. for 36 hours, we get 1.5 asFixedPoint:1 )
+ %(dw) days in week
+ %(hR) hours rounded (i.e. for 3h 30m, we get 3.5 asFixedPoint:1 )
+ %(mR) minutes rounded (i.e. for 2m 30s, we get 2.5 asFixedPoint:1 )
+ %(sR) seconds rounded to 1 postDecimal (i.e. for 2s 100ms, we get 2.1 asFixedPoint:1 )
"
- |hoursInDay s yearsRounded monthsRounded daysRounded hoursRounded minutesRounded secondsRounded|
+ |hoursInDay s yearsRounded monthsRounded weeksRounded daysRounded hoursRounded minutesRounded secondsRounded|
self addBasicPrintBindingsTo:aDictionary language:languageOrNil.
aDictionary at:$d put:self days.
@@ -702,13 +707,15 @@
aDictionary at:#Hd put:(s := hoursInDay printString).
aDictionary at:#hd put:(s leftPaddedTo:2 with:$0).
+ aDictionary at:#dw put:(self days \\ 7).
+
yearsRounded := (self hours / 24 / 365).
yearsRounded isInteger ifFalse:[
yearsRounded := yearsRounded asFixedPoint:1.
].
aDictionary at:#yrR put:yearsRounded.
- monthsRounded := (self hours / 24 / 30).
+ monthsRounded := self days / 30.
monthsRounded isInteger ifFalse:[
monthsRounded := monthsRounded asFixedPoint:1.
monthsRounded roundedToScale = monthsRounded asInteger ifTrue:[
@@ -717,6 +724,16 @@
].
aDictionary at:#monR put:monthsRounded.
+ aDictionary at:#w put:(self days // 7).
+ weeksRounded := self days / 7.
+ weeksRounded isInteger ifFalse:[
+ weeksRounded := weeksRounded asFixedPoint:1.
+ weeksRounded roundedToScale = weeksRounded asInteger ifTrue:[
+ weeksRounded := weeksRounded truncated
+ ].
+ ].
+ aDictionary at:#wR put:weeksRounded.
+
daysRounded := (self hours / 24).
daysRounded isInteger ifFalse:[
daysRounded := daysRounded asFixedPoint:1.
@@ -844,6 +861,7 @@
(TimeDuration readFrom:'10h 3s') formatForPrinting
(TimeDuration readFrom:'3s') formatForPrinting
(TimeDuration readFrom:'1d 2ms') formatForPrinting
+ (TimeDuration readFrom:'1 week') formatForPrinting
"
!
@@ -993,15 +1011,30 @@
"Return a format which is suitable for a human - not meant to be read back.
If shortFlag is true, some millisecond-info is ommitted for longer times."
- |fmt days hours mins secs overAllSeconds millis|
+ |fmt days weeks hours mins secs overAllSeconds millis|
days := self days.
+ weeks := days // 7.
hours := self hours.
mins := self minutes.
secs := self seconds.
millis := self milliseconds.
- ((days > 0) or:[hours >= 24]) ifTrue:[
+ weeks > 0 ifTrue:[
+ fmt := '%(w)w %(dw)d %(Hd)h %Mm'.
+ secs = 0 ifTrue:[
+ fmt := '%(w)w %(dw)d %(Hd)h %Mm'.
+ mins = 0 ifTrue:[
+ fmt := '%(w)w %(dw)d %(Hd)h'.
+ (hours \\ 24) = 0 ifTrue:[
+ fmt := '%(w)w %(dw)d'.
+ (days \\ 7) = 0 ifTrue:[
+ fmt := '%(w)w'.
+ ].
+ ].
+ ].
+ ].
+ ] ifFalse:[days > 0 ifTrue:[
fmt := '%dd %(Hd)h %Mm'.
secs = 0 ifTrue:[
fmt := '%dd %(Hd)h %Mm'.
@@ -1031,7 +1064,7 @@
fmt := ''
].
].
- ].
+ ]].
((secs ~= 0) or:[millis ~= 0])ifTrue:[
fmt size ~~ 0 ifTrue:[
fmt := fmt , ' '