summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>1999-07-04 08:54:26 +0000
committerobrien <obrien@FreeBSD.org>1999-07-04 08:54:26 +0000
commit091bed9159054b10d7290461e8d6634d95f294f2 (patch)
tree04264246bc74f4e8bb86fe040a9ad5962dac0bba /lib
parente49a79514f79deb4a0c2396c334dc7158edb95b1 (diff)
downloadFreeBSD-src-091bed9159054b10d7290461e8d6634d95f294f2.zip
FreeBSD-src-091bed9159054b10d7290461e8d6634d95f294f2.tar.gz
Actually impliment the documented %Z specifier.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdtime/strptime.313
-rw-r--r--lib/libc/stdtime/strptime.c33
2 files changed, 44 insertions, 2 deletions
diff --git a/lib/libc/stdtime/strptime.3 b/lib/libc/stdtime/strptime.3
index 8e74a13..99568c9 100644
--- a/lib/libc/stdtime/strptime.3
+++ b/lib/libc/stdtime/strptime.3
@@ -23,7 +23,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Id: strptime.3,v 1.3 1999/04/25 01:42:18 wes Exp $
+.\" $Id: strptime.3,v 1.4 1999/04/25 07:28:39 wes Exp $
.\" "
.Dd May 8, 1997
.Dt STRPTIME 3
@@ -44,6 +44,7 @@ according to the string pointed to by
.Fa format ,
and fills in the elements of the structure pointed to by
.Fa timeptr .
+The resulting values will be relative to the local time zone.
Thus, it can be considered the reverse operation of
.Xr strftime 3 .
.Pp
@@ -91,3 +92,13 @@ The
.Fn strptime
function appeared in
.Fx 3.0 .
+.Pp
+.Sh BUGS
+The
+.Fa %Z
+format specifier only accepts time zone abbreviations of the local time zone,
+or the value "GMT".
+This limitation is because of ambiguity due to of the over loading of time
+zone abbreviations. One such example is
+.Fa EST
+which is both Eastern Standard Time and Eastern Australia Summer Time.
diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c
index 27437fe..34da06e 100644
--- a/lib/libc/stdtime/strptime.c
+++ b/lib/libc/stdtime/strptime.c
@@ -53,7 +53,7 @@
#ifdef LIBC_RCS
static const char rcsid[] =
- "$Id: strptime.c,v 1.5 1999/04/25 01:42:18 wes Exp $";
+ "$Id: strptime.c,v 1.6 1999/04/25 07:28:39 wes Exp $";
#endif
#ifndef lint
@@ -71,6 +71,8 @@ static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
#define asizeof(a) (sizeof (a) / sizeof ((a)[0]))
+static int got_GMT = 0;
+
char *
strptime(const char *buf, const char *fmt, struct tm *tm)
{
@@ -344,8 +346,37 @@ strptime(const char *buf, const char *fmt, struct tm *tm)
while (*ptr != 0 && !isspace((unsigned char)*ptr))
ptr++;
break;
+
+ case 'Z':
+ {
+ const char *cp;
+ char *zonestr;
+
+ for (cp = buf; *cp && isupper(*cp); ++cp) {/*empty*/}
+ if (cp - buf) {
+ zonestr = alloca(cp - buf + 1);
+ strncpy(zonestr, buf, cp - buf);
+ zonestr[cp - buf] = '\0';
+ tzset();
+ if (0 == strcmp(zonestr, "GMT")) {
+ got_GMT = 1;
+ } else if (0 == strcmp(zonestr, tzname[0])) {
+ tm->tm_isdst = 0;
+ } else if (0 == strcmp(zonestr, tzname[1])) {
+ tm->tm_isdst = 1;
+ } else {
+ return 0;
+ }
+ buf += cp - buf;
+ }
+ }
+ break;
}
}
+ if (got_GMT) {
+ time_t t = timegm(tm);
+ localtime_r(&t, tm);
+ }
return (char *)buf;
}
OpenPOWER on IntegriCloud