【发布时间】:2021-04-11 03:08:40
【问题描述】:
源于这个问题gnuplot why warning: Bad time format in string,
发现在 gnuplot 中使用时间说明符 %W 和 %U 的周数在某些情况下是错误的。
显然,周数有不同的定义。 此外,一周开始时有不同的定义,例如周日或周一。 根据 ISO 8601,一种常用的周数定义(但在美国和少数其他国家/地区不适用)。
代码:(用于说明错误的周数)
### wrong week numbering in gnuplot with %W and %U
reset session
StartDate = "24.12.2020"
myTimeFmt = "%d.%m.%Y"
SecondsPerDay = 3600*24
print " date %a %w %d %j %W %U"
print "===================================="
do for [i=0:20] {
t = strptime(myTimeFmt,StartDate) + i*SecondsPerDay
myDate = strftime(myTimeFmt." %a %w %d %j %W %U", t)
print sprintf("%s", myDate)
}
### end of code
gnuplot 时间说明符:
%a abbreviated name of day of the week
%w day of the week, 0–6 (Sunday = 0)
%d day of the month, 01–31
%j day of the year, 1–366
%W week of the year (week starts on Monday)
%U week of the year (week starts on Sunday)
结果:
date %a %w %d %j %W %U
====================================
24.12.2020 Thu 04 24 359 52 52
25.12.2020 Fri 05 25 360 52 52
26.12.2020 Sat 06 26 361 52 52
27.12.2020 Sun 00 27 362 52 53
28.12.2020 Mon 01 28 363 53 53
29.12.2020 Tue 02 29 364 53 53
30.12.2020 Wed 03 30 365 53 53
31.12.2020 Thu 04 31 366 53 53
01.01.2021 Fri 05 01 001 01 01 ???
02.01.2021 Sat 06 02 002 01 01 ???
03.01.2021 Sun 00 03 003 00 01 ???
04.01.2021 Mon 01 04 004 01 01
05.01.2021 Tue 02 05 005 01 01
06.01.2021 Wed 03 06 006 01 01
07.01.2021 Thu 04 07 007 01 01
08.01.2021 Fri 05 08 008 01 01
09.01.2021 Sat 06 09 009 01 01
10.01.2021 Sun 00 10 010 01 02
11.01.2021 Mon 01 11 011 02 02
12.01.2021 Tue 02 12 012 02 02
13.01.2021 Wed 03 13 013 02 02
问题:有解决方法吗?
【问题讨论】:
标签: gnuplot week-number