summaryrefslogtreecommitdiffstats
path: root/main/musl/1003-implement-y-and-C-specifiers-in-strptime.patch
blob: 8bb18aa164a260bcbbcdfafbcbe5e423a773dced (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From 0caec05b829d1a2db1b559305a41770d9015042d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Wed, 14 May 2014 10:53:56 +0300
Subject: [PATCH] implement %y and %C specifiers in strptime

also return error if encountering an unknown recognized specifier.
---
 src/time/strptime.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/time/strptime.c b/src/time/strptime.c
index d1d141e..5ed40ca 100644
--- a/src/time/strptime.c
+++ b/src/time/strptime.c
@@ -11,6 +11,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
 	int i, w, neg, adj, min, range, *dest;
 	const char *ex;
 	size_t len;
+	int century = -2;
 	while (*f) {
 		if (*f != '%') {
 			if (isspace(*f)) for (; *s && isspace(*s); s++);
@@ -40,6 +41,9 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
 			if (!s) return 0;
 			break;
 		case 'C':
+			dest = &century;
+			if (w<0) w=2;
+			goto numeric_digits;
 		case 'd': case 'e':
 			dest = &tm->tm_mday;
 			min = 1;
@@ -128,16 +132,21 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
 			if (!s) return 0;
 			break;
 		case 'y':
-			//FIXME
-			return 0;
+			dest = &tm->tm_year;
+			if (w<0) w=2;
+			if (century==-2) century=-1;
+			goto numeric_digits;
 		case 'Y':
 			dest = &tm->tm_year;
 			if (w<0) w=4;
 			adj = 1900;
+			century = -2;
 			goto numeric_digits;
 		case '%':
 			if (*s++ != '%') return 0;
 			break;
+		default:
+			return 0;
 		numeric_range:
 			if (!isdigit(*s)) return 0;
 			*dest = 0;
@@ -176,5 +185,9 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
 			;
 		}
 	}
+	if (century >= -1) {
+		if (century >= 0) tm->tm_year += century * 100 - 1900;
+		else if (tm->tm_year <= 68) tm->tm_year += 100;
+	}
 	return (char *)s;
 }
-- 
1.9.2