zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: initialise day of month in datetime module
Date: Fri, 03 Jul 2015 22:48:18 +0200	[thread overview]
Message-ID: <9855.1435956498@thecus.kiddle.eu> (raw)

Note the following:

  % strftime '%F %T' $(strftime -r '%Y%m' 201507)
  2015-06-30 00:00:00

In a struct tm, tm_mday starts at 1 and not 0 so it is better to
initialise it to 1 so the command above will instead return midnight on
the 1st July.

Oliver

diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index 63a04dc..d941667 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -53,10 +53,12 @@ reverse_strftime(char *nam, char **argv, char *scalar, int quiet)
      * to use the current timezone.  This is probably the best guess;
      * it's the one that will cause dates and times output by strftime
      * without the -r option and without an explicit timezone to be
-     * converted back correctly.
+     * converted back correctly. Additionally, tm_mday is set to 1
+     * as that and not 0 corresponds to the first of the month.
      */
     (void)memset(&tm, 0, sizeof(tm));
     tm.tm_isdst = -1;
+    tm.tm_mday = 1;
     endp = strptime(argv[1], argv[0], &tm);
 
     if (!endp) {


                 reply	other threads:[~2015-07-03 20:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9855.1435956498@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).