[plt-scheme] SRFI-19 and week-numbers
Hi all,
I was attempting to find the start of the current week
and decided I'd try SRFI-19. The behaviour of its
date-week-number puzzles me.
The documentation reads:
date-week-number date day-of-week-starting-week -> integer
The ordinal week of the year which holds this date, ignoring a first
partial week. 'Day-of-week-starting-week' is the integer
corresponding to the day of the week which is to be considered the
first day of the week (Sunday=0, Monday=1, etc.).
But see what happens:
(require (lib "19.ss" "srfi"))
; previous-date : date -> date
; subtract 24 hours
(define (previous-date date)
(time-monotonic->date
(subtract-duration
(date->time-monotonic date)
(make-time 'time-duration
0 ; nanoseconds
(* 60 60 24))))) ; seconds in a 24 hours
(define (loop date n)
(if (= n 0)
'()
(cons (list (date->string date)
; monday is the first day of the week in Denmark
(date-week-number date 1))
(loop (previous-date date) (- n 1)))))
> (loop (current-date) 15)
(("Sun Sep 25 18:28:13+0200 2005" 38)
("Sat Sep 24 18:28:45+0200 2005" 37)
("Fri Sep 23 18:29:17+0200 2005" 37)
("Thu Sep 22 18:29:49+0200 2005" 37)
("Wed Sep 21 18:30:21+0200 2005" 37)
("Tue Sep 20 18:30:53+0200 2005" 37)
("Mon Sep 19 18:31:25+0200 2005" 37)
("Sun Sep 18 18:31:57+0200 2005" 37) ; Huh?
("Sat Sep 17 18:32:29+0200 2005" 36)
("Fri Sep 16 18:33:01+0200 2005" 36)
("Thu Sep 15 18:33:33+0200 2005" 36)
("Wed Sep 14 18:34:05+0200 2005" 36)
("Tue Sep 13 18:34:37+0200 2005" 36)
("Mon Sep 12 18:35:09+0200 2005" 36)
("Sun Sep 11 18:35:41+0200 2005" 36))
Using 2 = tuesday as the first day give
the expected:
(("Sun Sep 25 18:24:44+0200 2005" 37)
("Sat Sep 24 18:25:16+0200 2005" 37)
("Fri Sep 23 18:25:48+0200 2005" 37)
("Thu Sep 22 18:26:20+0200 2005" 37)
("Wed Sep 21 18:26:52+0200 2005" 37)
("Tue Sep 20 18:27:24+0200 2005" 37)
("Mon Sep 19 18:27:56+0200 2005" 37) ; !
("Sun Sep 18 18:28:28+0200 2005" 36)
("Sat Sep 17 18:29:00+0200 2005" 36)
("Fri Sep 16 18:29:32+0200 2005" 36)
("Thu Sep 15 18:30:04+0200 2005" 36)
("Wed Sep 14 18:30:36+0200 2005" 36)
("Tue Sep 13 18:31:08+0200 2005" 36)
("Mon Sep 12 18:31:40+0200 2005" 36)
("Sun Sep 11 18:32:12+0200 2005" 35))
Am I misunderstanding the documentation,
or have I found a bug?
--
Jens Axel Søgaard