unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* possible bug in srfi-19 implementation (fix included)
@ 2002-09-27 12:03 joost
  2002-09-27 22:36 ` Thien-Thi Nguyen
  2002-10-13 16:22 ` Marius Vollmer
  0 siblings, 2 replies; 5+ messages in thread
From: joost @ 2002-09-27 12:03 UTC (permalink / raw)
  Cc: bug-guile

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: possible bug in srfi-19 implementation (fix included)
  2002-09-27 12:03 possible bug in srfi-19 implementation (fix included) joost
@ 2002-09-27 22:36 ` Thien-Thi Nguyen
  2002-10-13 16:22 ` Marius Vollmer
  1 sibling, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2002-09-27 22:36 UTC (permalink / raw)
  Cc: bug-guile

   From: joost@snow.nl
   Date: Fri, 27 Sep 2002 14:03:19 +0200

   (define (mydatetoweeknumber dt) [...])

   Is my solution acceptable? If not, is there anyone who can implement
   a better solution?

looks like your solution codifies ISO-8601, but srfi-19 does not specify
ISO-8601.  if it is possible to implement a "date-week-number-ISO-8601"
using srfi-19 date-week-number (perhaps by providing an appropriate
second arg to date-week-number), it would be good to include that as an
example in the documentation.  would you like to try this approach?

this is a separate issue from whether or not guile's (srfi srfi-19)
date-week-number implementation fulfills the srfi-19 specification.  i
see there is no test for that in test-suite/tests/srfi-19.test.  would
you like to write one?

thi


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: possible bug in srfi-19 implementation (fix included)
  2002-09-27 12:03 possible bug in srfi-19 implementation (fix included) joost
  2002-09-27 22:36 ` Thien-Thi Nguyen
@ 2002-10-13 16:22 ` Marius Vollmer
  2002-10-14  8:12   ` Joost Helberg
  1 sibling, 1 reply; 5+ messages in thread
From: Marius Vollmer @ 2002-10-13 16:22 UTC (permalink / raw)
  Cc: bug-guile

joost@snow.nl writes:

> 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.

I find this date mangling stuff quite confusing so I have to pass the
ball back to you: does our SRFI-10 implementation conform to the docs
at http://srfi.schemers.org/srfi-19/srfi-19.html?

If not, can you fix it? :-)

I think it would have been sensible for SRFI-19 to specify the first
week of a year the way ISO 8601 does, but it doesn't seem to do so,
right?

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: possible bug in srfi-19 implementation (fix included)
  2002-10-13 16:22 ` Marius Vollmer
@ 2002-10-14  8:12   ` Joost Helberg
  2002-10-14 23:02     ` Marius Vollmer
  0 siblings, 1 reply; 5+ messages in thread
From: Joost Helberg @ 2002-10-14  8:12 UTC (permalink / raw)
  Cc: bug-guile

Marius,

>>>>> "Marius" == Marius Vollmer <mvo@zagadka.ping.de> writes:
    > To: joost@snow.nl
    > Cc: bug-guile@gnu.org
    > Subject: Re: possible bug in srfi-19 implementation (fix included)
    > From: Marius Vollmer <mvo@zagadka.ping.de>
    > Date: 13 Oct 2002 18:22:50 +0200

    > joost@snow.nl writes:

    >> 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.

    > I find this date mangling stuff quite confusing so I have to pass the
    > ball back to you: does our SRFI-10 implementation conform to the docs
    > at http://srfi.schemers.org/srfi-19/srfi-19.html?

The implementation in guile-1.6.0 conforms to the standard as defined
in srfi-19. But, as weeknumbers are not continuously increasing, I
can't see any practical use for the srfi-19 week-number standard.

    > If not, can you fix it? :-)
Not necessary.

    > I think it would have been sensible for SRFI-19 to specify the first
    > week of a year the way ISO 8601 does, but it doesn't seem to do so,
    > right?

Yep. I started writing tests (as the tests for srfi-19 don't include
week-functions) for testing week-related functions. E.g. make sure
that if dates are 7 days apart, the week-number is 1 apart. This is
not the case in srfi-19, as several years have 2 weeks 0.

Is there a way to extend srfi-19, or to make up a new one?

Joost

-- 
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: possible bug in srfi-19 implementation (fix included)
  2002-10-14  8:12   ` Joost Helberg
@ 2002-10-14 23:02     ` Marius Vollmer
  0 siblings, 0 replies; 5+ messages in thread
From: Marius Vollmer @ 2002-10-14 23:02 UTC (permalink / raw)
  Cc: bug-guile

Joost Helberg <joost@snow.nl> writes:

>     > If not, can you fix it? :-)
>
> Not necessary.

Ok, thanks!

> Is there a way to extend srfi-19, or to make up a new one?

I hope so.  I'm not really familiar with the SRFI process, but it
looks like you need to start a new SRFI to bugfix an existing final
one.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-10-14 23:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-27 12:03 possible bug in srfi-19 implementation (fix included) joost
2002-09-27 22:36 ` Thien-Thi Nguyen
2002-10-13 16:22 ` Marius Vollmer
2002-10-14  8:12   ` Joost Helberg
2002-10-14 23:02     ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).