unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Trying to get friends with SRFI-19
@ 2020-07-20 21:27 tomas
  2020-07-22 21:20 ` [SOLVED] " tomas
  0 siblings, 1 reply; 2+ messages in thread
From: tomas @ 2020-07-20 21:27 UTC (permalink / raw)
  Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1703 bytes --]

Hi,

I'm trying to parse some stuff, part of which are date
strings of the form "20200106", i.e. "YYYYMMDD". Since
I don't trust my input too much (or rather, my understanding
of it), I'd like to get a slap when my assumptions fail.

So I'd like to validate the date string.

SRFI-19 seems to be my friend. After checking that
everything is numeric, I try (the example is the
sixth of January 2020, at noon):

  (make-date 0 0 0 12 06 01 2020 7200)
  => #<date nanosecond: 0 second: 0 minute: 0 hour: 12 day: 6 month: 1 year: 2020 zone-offset: 7200>

So far so good. But if I try a bogus date (say, instead of
month 01 I pick 32):

  (make-date 0 0 0 12 06 32 2020 7200)
  => #<date nanosecond: 0 second: 0 minute: 0 hour: 12 day: 6 month: 1 year: 2020 zone-offset: 7200>

Ahem. Make-date happily accepts a month 32. This was
some surprise for me :)

Next I tried converting the thing to a Julian day and
back. My idea was that the conversion would "normalize"
the date representation, and if `equal' yields #t, we
have a sensible date.

This fails because after the double-conversion, the
time zone offset has shifted from 7200 to 3600, and
the two dates aren't equal?:

  (define d (make-date 0 0 0 12 06 01 2020 7200)) ; as above
  d
  => <date nanosecond: 0 second: 0 minute: 0 hour: 12 day: 6 month: 1 year: 2020 zone-offset: 7200>

  (julian-day->date (date->julian-day d))
  => #<date nanosecond: 0 second: 0 minute: 0 hour: 11 day: 6 month: 1 year: 2020 zone-offset: 3600>

Obviously I am barking up the wrong tree (if it's
a tree at all).

Is there a canonical way to validate a date string?

Confused. Thanks for any hint.

Cheers
-- tomás  

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* [SOLVED] Trying to get friends with SRFI-19
  2020-07-20 21:27 Trying to get friends with SRFI-19 tomas
@ 2020-07-22 21:20 ` tomas
  0 siblings, 0 replies; 2+ messages in thread
From: tomas @ 2020-07-22 21:20 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 622 bytes --]

On Mon, Jul 20, 2020 at 11:27:03PM +0200, tomas@tuxteam.de wrote:
> Hi,
> 
> I'm trying to parse some stuff, part of which are date
> strings of the form "20200106", i.e. "YYYYMMDD" [...]

> Is there a canonical way to validate a date string?

I ended up rolling my own (and converting to SRFI-19 date
once validation says "OK").

Is there interest in such a thing? i.e.

 valid-date? (y m d) -> bool
 returns whether (y m d) is a valid Gregorian date.

I wouldn't mind putting it up somewhere, with a suitable
license.  OTOH, it's a whopping 36 lines or so, so perhaps
not worth it ;-D

Cheers
-- t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

end of thread, other threads:[~2020-07-22 21:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20 21:27 Trying to get friends with SRFI-19 tomas
2020-07-22 21:20 ` [SOLVED] " tomas

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