From: <tomas@tuxteam.de>
Cc: guile-user@gnu.org
Subject: Trying to get friends with SRFI-19
Date: Mon, 20 Jul 2020 23:27:03 +0200 [thread overview]
Message-ID: <20200720212703.GC31180@tuxteam.de> (raw)
[-- 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 --]
next reply other threads:[~2020-07-20 21:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-20 21:27 tomas [this message]
2020-07-22 21:20 ` [SOLVED] Trying to get friends with SRFI-19 tomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200720212703.GC31180@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).