-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,
I've come upon a need to deal with some time functionality, and the
current pair of functions timef/readUtc appear insufficient --
principally, because there exists no easy way to detect the current
timezone so as to manually perform the timezone adjustment to UTC.
Consequently, the following does not work:
[...]
currentTm <- now;
fmt <- return (timef "%x %T" currentTm);
error (case readUtc fmt of None => <xml/> | Some t => <xml>{[fmt]} -
{[t]}</xml>)
We should expect this to print the current time twice, however, if your
local time happens to not be in UTC, then you're going to get a timezone
adjustment, and two completely different times displayed!
I propose a 'readTime' function to exist in addition to 'readUtc' that
will simply read a formatted time string as though it were in local
time. I've attached a patch to implement just this when applied against
the latest Ur/Web from Mercurial. In my example above, replacing
'readUtc' with 'readTime' provides the expected behaviour, such that
readTime is properly an inverse of timef.
Thanks,
Gian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJNz8p7AAoJEDd5xfOXfbYMC4AIAMfc5jVTHlEOQjNRL3AuCRkY
8Z3XeEZUBIL9XgBSyp0FY+DAiRl7R8q+CypCWPaK7tViFVI27ObrvPEUw1U+h+S1
j1MXVmk7e9TslqF5jznXfUA7dAq7OFVZGzATuvUe8xs1/e+FJkwKm8VGwg5GGIZA
v0SpAaECzKpTnz2ZZNwywxWrllY/G+mTX2fvXz6/L4DcvMD+sbVqS72FdAacf44i
beoMrvNM3gsj7TP6Y9dtI5o7c7S21heh4SsYBzHSefRWSP9tn3mw3bbUSK4zmdT+
uKUAh+VEra5h35OZXnrI6t5q64Z7xjM9eL7zR4blc79B9zb637dkMByfpxiShzY=
=abPi
-----END PGP SIGNATURE-----
diff -r d674fb9499c4 include/urweb.h
--- a/include/urweb.h Fri May 06 20:51:40 2011 -0430
+++ b/include/urweb.h Sun May 15 13:28:17 2011 +0100
@@ -329,6 +329,7 @@
uw_Basis_string uw_queryString(uw_context);
uw_Basis_time *uw_Basis_readUtc(uw_context, uw_Basis_string);
+uw_Basis_time *uw_Basis_readTime(uw_context, uw_Basis_string);
void uw_isPost(uw_context);
uw_Basis_bool uw_Basis_currentUrlHasPost(uw_context);
diff -r d674fb9499c4 src/c/urweb.c
--- a/src/c/urweb.c Fri May 06 20:51:40 2011 -0430
+++ b/src/c/urweb.c Sun May 15 13:28:49 2011 +0100
@@ -3772,6 +3772,23 @@
return NULL;
}
+uw_Basis_time *uw_Basis_readTime(uw_context ctx, uw_Basis_string s) {
+ struct tm stm = {};
+ char *end = strchr(s, 0);
+ stm.tm_isdst = -1;
+
+ if (strptime(s, TIME_FMT_PG, &stm) == end || strptime(s, TIME_FMT, &stm) ==
end) {
+ uw_Basis_time *r = uw_malloc(ctx, sizeof(uw_Basis_time));
+
+ r->seconds = mktime(&stm);
+ r->microseconds = 0;
+
+ return r;
+ }
+ else
+ return NULL;
+}
+
static const char begin_xhtml[] = "<?xml version=\"1.0\" encoding=\"utf-8\"
?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html
xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
failure_kind uw_begin_onError(uw_context ctx, char *msg) {
diff -r d674fb9499c4 lib/ur/basis.urs
--- a/lib/ur/basis.urs Fri May 06 20:51:40 2011 -0430
+++ b/lib/ur/basis.urs Sun May 15 13:29:02 2011 +0100
@@ -147,6 +147,7 @@
val addSeconds : time -> int -> time
val timef : string -> time -> string (* Uses strftime() format string *)
val readUtc : string -> option time
+val readTime : string -> option time
(** * Encryption *)
_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur