Fractions of Seconds and ISO 8601 in LEIF 2.5

Article ID: 1213
Last updated: 07 Feb, 2008
Article ID: 1213
Last updated: 07 Feb, 2008
Revision: 1
Views: 2797
Posted: 01 Jan, 2000
by Dean J.
Updated: 07 Feb, 2008
by Dean J.
Problem


This article addresses the use of the ISO 8601 standard when converting a LEIF::DateTime to a string.  The standard permits the inclusion of fractions of seconds in addition to hours, minutes and seconds in the representation of time.  The basic form for time is: HHMMSS,ss or HH:MM:SS.ss where HH is hours, MM is minutes, SS is seconds and ss is the decimal fraction of a second.  ISO 8601 specifies that the character separating the seconds and the fractional seconds may be either a comma or a period.  When a LEIF::DateTime is converted to a string using the asString( ) method the string will use a comma as the separator.




Action


LEIF provides three overloaded versions of the asString( ) method for DateTime objects.  Two of these methods are passed a format string for converting the DateTime to a string.  The third method is passed a Format enum value. The format enum is defined as:

 

enum Format { iso8601, http };

 

The code below would display an ISO 8601 representation of the current date and time:

 

#include <rw/leif/core/DateTime.h>

 

LEIF::DateTime dt(LEIF::DateTime::setCurrentTime);

std::cout << "Current time is: " << dt.asString(LEIF::DateTime::iso8601).data() << std::endl;

 

 

The resulting string has a comma as the separator: 

Current time is: 2005-10-24T14:29:08,875-06:00

 

The DateTime constructor will accept either separator.  So the following statements will result in the same data being stored in each object.

 

LEIF::DateTime dtPeriod("2001-12-24T01:12:30.90", LEIF::DateTime::iso8601);

LEIF::DateTime dtComma("2001-12-24T01:12:30,90", LEIF::DateTime::iso8601);

 

If dtPeriod and dtComma are both coverted back to strings using asString( ) with the Format LEIF::DateTime::iso8601 both will result in equivalent strings with the comma.

 

Resulting string:  2001-12-24T01:12:30,090-07:00

 

A complete example is available to download:  click here to download

 

Reference:

LEIF Core Library Reference Guide ? LEIF::DateTime & LEIF::Locale

 

Essential Tools Module User's Guide ? 3.3 International Standards for Dates and Times

W3 Schools http://www.w3.org/TR/NOTE-datetime

Victoria University of Wellington http://www.mcs.vuw.ac.nz/technical/software/SGML/doc/iso8601/ISO8601.html

This article was:   Helpful | Not helpful
Report an issue
Article ID: 1213
Last updated: 07 Feb, 2008
Revision: 1
Views: 2797
Posted: 01 Jan, 2000 by Dean J.
Updated: 07 Feb, 2008 by Dean J.

Others in this category