|
2016-12-06
| ||
| 11:59 | • Deleted ticket [39dbdc4797]: [clock scan $year-$week-$dayofweek" -format &q... artifact: 23c53bccc2 user: anonymous | |
| 10:35 | • New ticket [39dbdc4797]. artifact: 1478c5a7d4 user: anonymous | |
[clock scan $year-$week-$dayofweek" -format "%G-%V-%u"] may be wrong on ISO Week >= 52
Deleted39dbdc4797797a69398fb3452250ec057c24cd02Created 10 years agoUpdated 10 years ago
Descriptionplain2016-12-06 10:35:44
When calculating an ISO8601 date in the form of "YYYY-MM-DD" from input of : Year (4 car), ISO Week (2 car), Day of week (integer from 1 to 7),
clock format [clock scan 2016-52-6 -format "%G-%V-%u"] -format "%G-%m-%d" gives the correct answer : 2016-12-31
However calculating the date of sunday on the same week goes wrong :
clock format [clock scan 2016-52-7 -format "%G-%V-%u"] -format "%G-%m-%d" returns 2016-01-01 instead of 2017-01-01
Issue observed on every year when the day-of-the-week points on a date *after* december-31.
To mitigate the pb, various (naive) combinaisons of [clock add] were tried but the date of 2017-01-01 seems unreachable by calculus from ISO week 52 of 2016.
Bellow is an unsuccessfull (and ugly) attempt to work around the pb were you can seen that [clock add +1 year] applied to (wrong) result of 2016-01-01 returns 2018-01-01
proc ConvWdate {An Sem Jr} {
# An = ISO Year (4 car)
# Sem = ISO Week (01 - 53)
# Jr = Day-of-week (1 car : A - G) (A = Monday ... G = Sunday)
if {$Sem ni {52 53}} {
switch $Jr {
A {return [clock format [clock scan "$An-$Sem-1" -format %G-%V-%u"] -format "%G-%m-%d"]}
B {return [clock format [clock scan "$An-$Sem-2" -format %G-%V-%u"] -format "%G-%m-%d"]}
C {return [clock format [clock scan "$An-$Sem-3" -format "%G-%V-%u"] -format "%G-%m-%d"]}
D {return [clock format [clock scan "$An-$Sem-4" -format "%G-%V-%u"] -format "%G-%m-%d"]}
E {return [clock format [clock scan "$An-$Sem-5" -format "%G-%V-%u"] -format "%G-%m-%d"]}
F {return [clock format [clock scan "$An-$Sem-6" -format "%G-%V-%u"] -format "%G-%m-%d"]}
G {return [clock format [clock scan "$An-$Sem-7" -format "%G-%V-%u"] -format "%G-%m-%d"]}
}
} else {
switch $Jr {
A {return [clock format [clock scan "$An-$Sem-1" -format "%G-%V-%u"] -format "%G-%m-%d"]}
B {if {[clock format [clock scan "$An-$Sem-2" -format "%G-%V-%u"] -format "%d"] eq "01"} then {return [clock format [clock add [clock scan "$An-$Sem-2" -format "%G-%V-%u"] 1 year] -format "%G-%m-%d"]} else {return [clock format [clock scan "$An-$Sem-2" -format "%G-%V-%u"] -format "%G-%m-%d"]}}
C {if {[clock format [clock scan "$An-$Sem-3" -format "%G-%V-%u"] -format "%d"] in {01 02}} then {return [clock format [clock add [clock scan "$An-$Sem-3" -format "%G-%V-%u"] 1 year] -format "%G-%m-%d"]} else {return [clock format [clock scan "$An-$Sem-3" -format "%G-%V-%u"] -format "%G-%m-%d"]}}
D {if {[clock format [clock scan "$An-$Sem-4" -format "%G-%V-%u"] -format "%d"] in {01 02 03}} then {return [clock format [clock add [clock scan "$An-$Sem-4" -format "%G-%V-%u"] 1 year] -format "%G-%m-%d"]} else {return [clock format [clock scan "$An-$Sem-4" -format "%G-%V-%u"] -format "%G-%m-%d"]}}
E {if {[clock format [clock scan "$An-$Sem-5" -format "%G-%V-%u"] -format "%d"] in {01 02 03 04}} then {return [clock format [clock add [clock scan "$An-$Sem-5" -format "%G-%V-%u"] 1 year] -format "%G-%m-%d"]} else {return [clock format [clock scan "$An-$Sem-5" -format "%G-%V-%u"] -format "%G-%m-%d"]}}
F {if {[clock format [clock scan "$An-$Sem-6" -format "%G-%V-%u"] -format "%d"] in {01 02 03 04 05}} then {return [clock format [clock add [clock scan "$An-$Sem-6" -format "%G-%V-%u"] 1 year] -format "%G-%m-%d"]} else {return [clock format [clock scan "$An-$Sem-6" -format "%G-%V-%u"] -format "%G-%m-%d"]}}
G {if {[clock format [clock scan "$An-$Sem-7" -format "%G-%V-%u"] -format "%d"] in {01 02 03 04 05 06}} then {return [clock format [clock add [clock scan "$An-$Sem-7" -format "%G-%V-%u"] 1 year] -format "%G-%m-%d"]} else {return [clock format [clock scan "$An-$Sem-7" -format "%G-%V-%u"] -format "%G-%m-%d"]}}
}
}
}
(sorry for ugly formating)
Jm Cuaz
anonymous (claiming to be Jm Cuaz)plain2016-12-06 11:59:24
I retract this ticket : my mistake about the year format specifier of [clock format] -> should be %Y instead of %G Appologies for false alarm Jm Cuaz
Log in (anonymous is fine) to add a comment.