unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: tantalum <sph@posteo.eu>
To: sirgazil@zoho.com
Cc: guile-user@gnu.org
Subject: How do you format date-times in RFC 3339 style?
Date: Tue, 12 Feb 2019 18:29:02 +0000	[thread overview]
Message-ID: <ea59cf45-18d6-574c-f84a-315c39102817@posteo.eu> (raw)

i once wrote a rfc3339 reader/writer and worked through some gotchas, maybe the code contains hints that are helpful.
for example, here is a function that converts from a timestamp to a rfc3339 date string:

   (define* (utc->rfc3339 a #:optional (offset 0) (seconds-fraction 0))
     "integer:posix-time -> string"
     (let
       ( (date-time
           (let (t (gmtime (+ a offset)))
             (apply
               (l (y m d h mi s)
                 (string-append y "-"
                   m "-"
                   d "T"
                   h ":"
                   mi ":"
                   s
                   (if (zero? seconds-fraction) ""
                     (string-append "." (number->string seconds-fraction)))))
               (map number->padded-string
                 (list (+ 1900 (tm:year t)) (+ 1 (tm:mon t))
                   (tm:mday t) (tm:hour t) (tm:min t) (tm:sec t))))))
         (offset
           (if (zero? offset) "Z"
             (apply
               (l (sign numbers)
                 (string-append sign (string-join (map number->padded-string numbers) ":")))
               (let* ((hms (drop-right (utc-duration->hms offset) 1)) (hours (first hms)))
                 (if (any negative? hms) (list "-" (map (l (a) (* -1 a)) hms)) (list "+" hms)))))))
       (string-append date-time offset)))

l: lambda, first: car

the code passes these tests (examples of valid strings):
https://github.com/sph-mn/sph-lib/blob/master/modules/test/module/sph/time/rfc3339.scm

for reference, the complete code: https://github.com/sph-mn/sph-lib/blob/master/modules/sph/time/rfc3339.scm



             reply	other threads:[~2019-02-12 18:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 18:29 tantalum [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-02-12 18:33 How do you format date-times in RFC 3339 style? tantalum
2019-02-13 14:21 ` sirgazil
2019-02-14 19:26   ` tantalum
2019-02-14 21:13     ` Ricardo Wurmus
2019-02-11 19:02 sirgazil
2019-02-11 21:39 ` Nala Ginrut
2019-02-11 21:40   ` Nala Ginrut
2019-02-12 14:33   ` sirgazil
2019-02-12 16:18     ` Nala Ginrut
2019-02-12 17:33       ` sirgazil
2019-02-12 16:50     ` Ricardo Wurmus
2019-02-12 18:15       ` sirgazil

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=ea59cf45-18d6-574c-f84a-315c39102817@posteo.eu \
    --to=sph@posteo.eu \
    --cc=guile-user@gnu.org \
    --cc=sirgazil@zoho.com \
    /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).