From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: joost@snow.nl Newsgroups: gmane.lisp.guile.bugs Subject: possible bug in srfi-19 implementation (fix included) Date: Fri, 27 Sep 2002 14:03:19 +0200 Sender: bug-guile-admin@gnu.org Message-ID: <20020927120319.A4014E2BE0F@tejo.snow.nl> Reply-To: joost@snow.nl NNTP-Posting-Host: localhost.gmane.org Content-Type: text/plain; charset=iso-8859-1 X-Trace: main.gmane.org 1033128236 9719 127.0.0.1 (27 Sep 2002 12:03:56 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 27 Sep 2002 12:03:56 +0000 (UTC) Cc: bug-guile@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17utqd-0002Wd-00 for ; Fri, 27 Sep 2002 14:03:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17utqo-0007vI-00; Fri, 27 Sep 2002 08:04:06 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17utqR-0007r7-00 for bug-guile@gnu.org; Fri, 27 Sep 2002 08:03:43 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17utqO-0007qv-00 for bug-guile@gnu.org; Fri, 27 Sep 2002 08:03:43 -0400 Original-Received: from neerijnen.snow.nl ([212.72.238.6]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17utqN-0007qr-00 for bug-guile@gnu.org; Fri, 27 Sep 2002 08:03:40 -0400 Original-Received: (from nobody@localhost) by neerijnen.snow.nl (8.8.8/8.6.9) id NAA22869; Fri, 27 Sep 2002 13:59:24 GMT Original-Received: by neerijnen.snow.nl via recvmail id 22863; Fri Sep 27 13:59:11 2002 Original-Received: from tejo.snow.nl (tejo.snow.nl [192.168.0.105]) by intern.snow.nl (Postfix) with ESMTP id EDE0E146038E; Fri, 27 Sep 2002 14:04:47 +0200 (CEST) Original-Received: from tejo (localhost [127.0.0.1]) by tejo.snow.nl (Postfix) with ESMTP id A4014E2BE0F; Fri, 27 Sep 2002 14:03:19 +0200 (CEST) Original-To: Rob Browning X-Comment: From at the beginning of a paragraph is replaced with +From Errors-To: bug-guile-admin@gnu.org X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GUILE, GNU's Ubiquitous Extension Language List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.lisp.guile.bugs:480 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.bugs:480 hi, I'm using guile-1.6.0 and srfi-19 for date stuff. It seems that the week-numbers are not calculated correctly, as it returns week 0 for all dates between 2002-1-1 and 2002-1-12. All other weeknumbers after the 12th are 2 off. This is the stuff to reproduce it: guile> (date-week-number (string->date "2002-1-23" "~Y-~m-~d") 1) 2 guile> (date-week-number (string->date "2002-1-16" "~Y-~m-~d") 1) 1 guile> (date-week-number (string->date "2002-1-9" "~Y-~m-~d") 1) 0 guile> (date-week-number (string->date "2002-1-3" "~Y-~m-~d") 1) 0 The problem occurs because of: guile> (priv:days-before-first-week (string->date "2002-1-1" "~Y-~m-~d") 1) 6 In the epxression: (define (date-week-number date day-of-week-starting-week) (quotient (- (date-year-day date) (priv:days-before-first-week date day-of-week-starting-week)) 7)) http://www.cl.cam.ac.uk/~mgk25/iso-time.html (ISO 8601) says: In commercial and industrial applications (delivery times, production plans, etc.), especially in Europe, it is often required to refer to a week of a year. Week 01 of a year is per definition the first week that has the Thursday in this year, which is equivalent to the week that contains the fourth day of January. In other words, the first week of a new year is the week that has the majority of its days in the new year. Week 01 might also contain days from the previous year and the week before week 01 of a year is the last week (52 or 53) of the previous year even if it contains days from the new year. A week starts with Monday (day 1) and ends with Sunday (day 7). For example, the first week of the year 1997 lasts from 1996-12-30 to 1997-01-05 and can be written in standard notation as................ I've seen this solution: If you know the date, how do you calculate the corresponding week number (as defined in ISO-8601)? 1) Using the formulas in section 2.15.1, calculate the Julian Day Number, J. 2) Perform the following calculations (in which the divisions are integer divisions in which the remainder is discarded): d4 = (J+31741 - (J mod 7)) mod 146097 mod 36524 mod 1461 L = d4/1460 d1 = ((d4-L) mod 365) + L WeekNumber = d1/7+1 in http://www.pauahtun.org/CalendarFAQ/cal/calendar24.txt. This leads to the implementation: (define (mydatetoweeknumber dt) (let* ((J (inexact->exact (date->julian-day dt))) (d4 (modulo (modulo (modulo (- (+ J 31741) (modulo J 7)) 146097) 36524) 1461)) (L (inexact->exact (/ d4 1460))) (d1 (+ (modulo (- d4 L) 365) L))) (+ (inexact->exact (/ d1 7)) 1) ) ) Is my solution acceptable? If not, is there anyone who can implement a better solution? regards, Joost Helberg -- Joost Helberg Technisch Directeur Snow BV http://snow.nl Tel 0418-653333 Fax 0418-653666 Voorzitter VOSN http://www.vosn.nl Tel 0418-653336 Fax 0418-653666 GPG PblKey fprnt= 738C 20AC A545 02AE 6F5D 5A9F D724 EB4B 2B10 150B _______________________________________________ Bug-guile mailing list Bug-guile@gnu.org http://mail.gnu.org/mailman/listinfo/bug-guile