mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [PATCH] implement strftime GNU extension padding specifiers '_', '-' and '0'
Date: Sat, 9 Dec 2017 18:27:39 -0500	[thread overview]
Message-ID: <20171209232739.GB1627@brightrain.aerifal.cx> (raw)
In-Reply-To: <20171209225650.GA1627@brightrain.aerifal.cx>

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

On Sat, Dec 09, 2017 at 05:56:50PM -0500, Rich Felker wrote:
> If you're tired of working and waiting on this and just want me to
> commit it as-is and make any improvements later, just let me know.
> I'll try to adapt the (freeform, non-checking) tests I did into
> something that can go into libc-test.

Attached is my first draft of what could go in libc-test. It doesn't
cover any subtleties of value computation, only formatting.

Rich

[-- Attachment #2: strftime.c --]
[-- Type: text/plain, Size: 1732 bytes --]

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include "test.h"

#define T1 3724

static const struct {
	time_t t;
	const char *fmt;
	const char *expect;
} tests[] = {
	{ T1, "%a", "Thu" },
	{ T1, "%A", "Thursday" },
	{ T1, "%b", "Jan" },
	{ T1, "%B", "January" },
	{ T1, "%c", "Thu Jan  1 01:02:04 1970" },
	{ T1, "%C", "19" },
	{ T1, "%04C", "0019" },
	//{ T1, "%+4C", "0019" }, // correct?
	{ T1, "%d", "01" },
	{ T1, "%D", "01/01/70" },
	{ T1, "%e", " 1" },
	{ T1, "%F", "1970-01-01" },
	{ T1, "%012F", "001970-01-01" },
	// { T1, "%+12F", "001970-01-01" }, //correct?
	{ T1, "%g", "70" },
	{ T1, "%G", "1970" },
	{ T1, "%06G", "001970" },
	// { T1, "%+6G", "001970" }, // correct?
	{ T1, "%h", "Jan" },
	{ T1, "%H", "01" },
	{ T1, "%I", "01" },
	{ T1, "%j", "001" },
	{ T1, "%m", "01" },
	{ T1, "%M", "02" },
	{ T1, "%n", "\n" },
	{ T1, "%p", "AM" },
	{ T1, "%r", "01:02:04 AM" },
	{ T1, "%R", "01:02" },
	{ T1, "%s", "3724" },
	{ T1, "%S", "04" },
	{ T1, "%T", "01:02:04" },
	{ T1, "%u", "4" },
	{ T1, "%U", "00" },
	{ T1, "%V", "01" },
	{ T1, "%w", "4" },
	{ T1, "%W", "00" },
	{ T1, "%x", "01/01/70" },
	{ T1, "%X", "01:02:04" },
	{ T1, "%Y", "1970" },
	{ T1, "%06Y", "001970" },
	// { T1, "%+6Y", "001970" }, //correct ?
};

int main(int argc, char **argv)
{
	for (size_t i=0; i<sizeof tests/sizeof *tests; i++) {
		time_t t = tests[i].t;
		struct tm *tm = gmtime(&t);
		char buf[500];
		size_t n = strftime(buf, sizeof buf, tests[i].fmt, tm);
		size_t l = strlen(tests[i].expect);
		if (n != l)
			t_error("strftime returned %zu expected %zu\n", n, l);
		if (n && strcmp(buf, tests[i].expect))
			t_error("strftime wrote '%s' expected '%s'\n", buf, tests[i].expect);
	}

	return t_status;
}

      reply	other threads:[~2017-12-09 23:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22  8:29 Timo Teräs
2016-12-20 20:13 ` Rich Felker
2016-12-21  0:27   ` Felix Janda
2016-12-21  3:20     ` Rich Felker
2017-01-06  6:59       ` [PATCH v2] " Timo Teräs
2016-12-21  6:01     ` [PATCH] " Timo Teras
2017-12-09 22:56 ` Rich Felker
2017-12-09 23:27   ` Rich Felker [this message]

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=20171209232739.GB1627@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

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

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