Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: initialise day of month in datetime module
- X-seq: zsh-workers 35681
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: initialise day of month in datetime module
- Date: Fri, 03 Jul 2015 22:48:18 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1435956499; bh=H2Mu4GOf9AEK5l2a8umLt+g8ZVsKyGQmb3iiKX+YfvM=; h=From:To:Subject:Date:From:Subject; b=nRCipVrU3EgMwxfWSDHDV/+RmE9WxUvk/wV13FFPhKStspiPU0B5nLrLBpt/v7WB3s/H7SLSOv8gd3hnWWmbYpkt97Erjt/CH+Jxn8emGR2PMEh9oNDu4bsqVj2OK04f1FSwWWhHQPcUONbdcOJ1tKf9lucu7Bv3HX7NxhsD4KM+E3BOuOpemxQI8oTCIMrW8f55nYX1umTLoHjMr466VP+P/RZ8UTKwD46pFcfDpYGw5rZL7fq4lohq/It9rHRcG4e2chbfgSXGehtP783wX6VSaktWapKU/L08+ZaSitqaX/xYjAvrlwtvAtlTO9vGMj1zZ8jz+9hPiyaYj4A1Iw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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) {
Messages sorted by:
Reverse Date,
Date,
Thread,
Author