* Foundation/include/Poco/LocalDateTime.h

* Foundation/src/LocalDateTime.cpp
  - Fixed Sourceforge tracker 1800031.
    The time zone differential was not being maintained in many places.
    There are some minor functionality changes with this changeset however.
    * Assignment methods which do not take the full time information or a
      tzd as parameters will adjust the time stamp for DST according to
      the time specified. The only methods that do not fall under this
      constraint are:
      - constructors or assigns which accept year, month, day, etc.
      - constructors or assigns which accept a tzd
    * operators += and -= correctly adjust for DST boundary crossings.
    * operators + and - will return a LocalDateTime instance that has
      been adjust for DST boundary crossings.
* Foundation/testsuite/src/LocalDateTimeTest.h
* Foundation/testsuite/src/LocalDateTimeTest.cpp
  - Added testTimezone method.
  - Removed an assertion in testGregorian1() that would fail when the
    current DST offset differed from that of 1970-1-1.
This commit is contained in:
David Shawley
2007-10-01 03:09:05 +00:00
parent d9364e8f51
commit 01d998dcc2
4 changed files with 184 additions and 26 deletions

View File

@@ -64,6 +64,14 @@ class Foundation_API LocalDateTime
/// class for better performance. The relational operators
/// normalize the dates/times involved to UTC before carrying out
/// the comparison.
///
/// The time zone differential is based on the input date and
/// time and current time zone. A number of constructors accept
/// an explicit time zone differential parameter. These should
/// not be used since daylight savings time processing is impossible
/// since the time zone is unknown. Each of the constructors
/// accepting a tzd parameter have been marked as deprecated and
/// may be removed in a future revision.
{
public:
LocalDateTime();
@@ -81,6 +89,7 @@ public:
/// * millisecond is from 0 to 999.
/// * microsecond is from 0 to 999.
//@ deprecated
LocalDateTime(int tzd, int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond);
/// Creates a DateTime for the given Gregorian date and time in the
/// time zone denoted by the time zone differential in tzd.
@@ -98,11 +107,13 @@ public:
/// Creates a LocalDateTime from the UTC time given in dateTime,
/// using the time zone differential of the current time zone.
//@ deprecated
LocalDateTime(int tzd, const DateTime& dateTime);
/// Creates a LocalDateTime from the UTC time given in dateTime,
/// using the given time zone differential. Adjusts dateTime
/// for the given time zone differential.
//@ deprecated
LocalDateTime(int tzd, const DateTime& dateTime, bool adjust);
/// Creates a LocalDateTime from the UTC time given in dateTime,
/// using the given time zone differential. If adjust is true,
@@ -111,6 +122,7 @@ public:
LocalDateTime(double julianDay);
/// Creates a LocalDateTime for the given Julian day in the local time zone.
//@ deprecated
LocalDateTime(int tzd, double julianDay);
/// Creates a LocalDateTime for the given Julian day in the time zone
/// denoted by the time zone differential in tzd.
@@ -141,6 +153,7 @@ public:
/// * millisecond is from 0 to 999.
/// * microsecond is from 0 to 999.
//@ deprecated
LocalDateTime& assign(int tzd, int year, int month, int day, int hour, int minute, int second, int millisecond, int microseconds);
/// Assigns a Gregorian local date and time in the time zone denoted by
/// the time zone differential in tzd.
@@ -154,6 +167,7 @@ public:
/// * millisecond is from 0 to 999.
/// * microsecond is from 0 to 999.
//@ deprecated
LocalDateTime& assign(int tzd, double julianDay);
/// Assigns a Julian day in the time zone denoted by the
/// time zone differential in tzd.
@@ -245,6 +259,13 @@ public:
protected:
LocalDateTime(Timestamp::UtcTimeVal utcTime, Timestamp::TimeDiff diff, int tzd);
void determineTzd (bool adjust = false);
/// Recalculate the tzd based on the _dateTime member based
/// on the current timezone using the Standard C runtime functions.
/// If adjust is true, then adjustForTzd() is called after the
/// differential is calculated.
void adjustForTzd();
/// Adjust the _dateTime member based on the _tzd member.
private:
DateTime _dateTime;
@@ -364,6 +385,12 @@ inline Timestamp::UtcTimeVal LocalDateTime::utcTime() const
}
inline void LocalDateTime::adjustForTzd()
{
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
}
inline void swap(LocalDateTime& d1, LocalDateTime& d2)
{
d1.swap(d2);