tango.text.convert.TimeStamp

License:

BSD style: see license.txt

Version:

Initial release: May 2005

Author:

Kris

Converts between native and text representations of HTTP time values. Internally, time is represented as UTC with an epoch fixed at Jan 1st 1970. The text representation is formatted in accordance with RFC 1123, and the parser will accept one of RFC 1123, RFC 850, or asctime formats.

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html for further detail.

Applying the D "import alias" mechanism to this module is highly recommended, in order to limit namespace pollution:
1
2
3
import TimeStamp = tango.text.convert.TimeStamp;

auto t = TimeStamp.parse ("Sun, 06 Nov 1994 08:49:37 GMT");
ulong toTime(T)(T[] src)
Parse provided input and return a UTC epoch time. An exception is raised where the provided string is not fully parsed.
char[] toString(Time time)
Template wrapper to make life simpler. Returns a text version of the provided value.
See format() for details
wchar[] toString16(Time time)
Template wrapper to make life simpler. Returns a text version of the provided value.
See format() for details
dchar[] toString32(Time time)
Template wrapper to make life simpler. Returns a text version of the provided value.
See format() for details
T[] format(T, U = Time)(T[] output, U t)
RFC1123 formatted time
Converts to the format "Sun, 06 Nov 1994 08:49:37 GMT", and returns a populated slice of the provided buffer. Note that RFC1123 format is always in absolute GMT time, and a thirty- element buffer is sufficient for the produced output

Throws an exception where the supplied time is invalid
T[] format8601(T, U = Time)(T[] output, U t)
ISO-8601 format :: "2006-01-31T14:49:30Z"
Throws an exception where the supplied time is invalid
Time parse(T)(T[] src, size_t* ate = null)
Parse provided input and return a UTC epoch time. A return value of Time.max (or false, respectively) indicated a parse-failure.
An option is provided to return the count of characters parsed - an unchanged value here also indicates invalid input.
bool parse(T)(T[] src, ref TimeOfDay tod, ref Date date, size_t* ate = null)
Parse provided input and return a UTC epoch time. A return value of Time.max (or false, respectively) indicated a parse-failure.
An option is provided to return the count of characters parsed - an unchanged value here also indicates invalid input.
size_t rfc1123(T)(T[] src, ref Time value)
RFC 822, updated by RFC 1123 :: "Sun, 06 Nov 1994 08:49:37 GMT"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t rfc1123(T)(T[] src, ref TimeOfDay tod, ref Date date)
RFC 822, updated by RFC 1123 :: "Sun, 06 Nov 1994 08:49:37 GMT"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t rfc850(T)(T[] src, ref Time value)
RFC 850, obsoleted by RFC 1036 :: "Sunday, 06-Nov-94 08:49:37 GMT"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t rfc850(T)(T[] src, ref TimeOfDay tod, ref Date date)
RFC 850, obsoleted by RFC 1036 :: "Sunday, 06-Nov-94 08:49:37 GMT"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t asctime(T)(T[] src, ref Time value)
ANSI C's asctime() format :: "Sun Nov 6 08:49:37 1994"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t asctime(T)(T[] src, ref TimeOfDay tod, ref Date date)
ANSI C's asctime() format :: "Sun Nov 6 08:49:37 1994"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t dostime(T)(T[] src, ref Time value)
DOS time format :: "12-31-06 08:49AM"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t dostime(T)(T[] src, ref TimeOfDay tod, ref Date date)
DOS time format :: "12-31-06 08:49AM"
Returns the number of elements consumed by the parse; zero if the parse failed
size_t iso8601(T)(T[] src, ref Time value)
ISO-8601 format :: "2006-01-31 14:49:30,001"
Returns the number of elements consumed by the parse; zero if the parse failed

Quote from http://en.wikipedia.org/wiki/ISO_8601 (2009-09-01): "Decimal fractions may also be added to any of the three time elements. A decimal point, either a comma or a dot (without any preference as stated most recently in resolution 10 of the 22nd General Conference CGPM in 2003), is used as a separator between the time element and its fraction."
size_t iso8601(T)(T[] src, ref TimeOfDay tod, ref Date date)
ISO-8601 format :: "2006-01-31 14:49:30,001"
Returns the number of elements consumed by the parse; zero if the parse failed

Quote from http://en.wikipedia.org/wiki/ISO_8601 (2009-09-01): "Decimal fractions may also be added to any of the three time elements. A decimal point, either a comma or a dot (without any preference as stated most recently in resolution 10 of the 22nd General Conference CGPM in 2003), is used as a separator between the time element and its fraction."