4
// $Id: //poco/1.2/Foundation/src/LocalDateTime.cpp#1 $
8
// Module: LocalDateTime
10
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13
// Permission is hereby granted, free of charge, to any person or organization
14
// obtaining a copy of the software and accompanying documentation covered by
15
// this license (the "Software") to use, reproduce, display, distribute,
16
// execute, and transmit the Software, and to prepare derivative works of the
17
// Software, and to permit third-parties to whom the Software is furnished to
18
// do so, all subject to the following:
20
// The copyright notices in the Software and this entire statement, including
21
// the above license grant, this restriction and the following disclaimer,
22
// must be included in all copies of the Software, in whole or in part, and
23
// all derivative works of the Software, unless such copies or derivative
24
// works are solely in the form of machine-executable object code generated by
25
// a source language processor.
27
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
30
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
31
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
32
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33
// DEALINGS IN THE SOFTWARE.
37
#include "Poco/LocalDateTime.h"
38
#include "Poco/Timezone.h"
39
#include "Poco/Timespan.h"
46
LocalDateTime::LocalDateTime():
49
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
53
LocalDateTime::LocalDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond):
54
_dateTime(year, month, day, hour, minute, second, millisecond, microsecond),
60
LocalDateTime::LocalDateTime(int tzd, int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond):
61
_dateTime(year, month, day, hour, minute, second, millisecond, microsecond),
67
LocalDateTime::LocalDateTime(double julianDay):
71
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
75
LocalDateTime::LocalDateTime(int tzd, double julianDay):
79
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
83
LocalDateTime::LocalDateTime(const DateTime& dateTime):
87
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
91
LocalDateTime::LocalDateTime(int tzd, const DateTime& dateTime):
95
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
99
LocalDateTime::LocalDateTime(const LocalDateTime& dateTime):
100
_dateTime(dateTime._dateTime),
106
LocalDateTime::LocalDateTime(Timestamp::UtcTimeVal utcTime, Timestamp::TimeDiff diff, int tzd):
107
_dateTime(utcTime, diff),
113
LocalDateTime::~LocalDateTime()
118
LocalDateTime& LocalDateTime::operator = (const LocalDateTime& dateTime)
120
if (&dateTime != this)
122
_dateTime = dateTime._dateTime;
123
_tzd = dateTime._tzd;
129
LocalDateTime& LocalDateTime::operator = (const Timestamp& timestamp)
131
if (timestamp != this->timestamp())
132
_dateTime = timestamp;
138
LocalDateTime& LocalDateTime::operator = (double julianDay)
140
_tzd = Timezone::tzd();
141
_dateTime = julianDay;
142
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
147
LocalDateTime& LocalDateTime::assign(int year, int month, int day, int hour, int minute, int second, int millisecond, int microseconds)
149
_dateTime.assign(year, month, day, hour, minute, second, millisecond, microseconds);
150
_tzd = Timezone::tzd();
155
LocalDateTime& LocalDateTime::assign(int tzd, int year, int month, int day, int hour, int minute, int second, int millisecond, int microseconds)
157
_dateTime.assign(year, month, day, hour, minute, second, millisecond, microseconds);
163
LocalDateTime& LocalDateTime::assign(int tzd, double julianDay)
166
_dateTime = julianDay;
167
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
172
void LocalDateTime::swap(LocalDateTime& dateTime)
174
_dateTime.swap(dateTime._dateTime);
175
std::swap(_tzd, dateTime._tzd);
179
DateTime LocalDateTime::utc() const
181
return DateTime(_dateTime.utcTime(), -((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
185
bool LocalDateTime::operator == (const LocalDateTime& dateTime) const
187
return utcTime() == dateTime.utcTime();
191
bool LocalDateTime::operator != (const LocalDateTime& dateTime) const
193
return utcTime() != dateTime.utcTime();
197
bool LocalDateTime::operator < (const LocalDateTime& dateTime) const
199
return utcTime() < dateTime.utcTime();
203
bool LocalDateTime::operator <= (const LocalDateTime& dateTime) const
205
return utcTime() <= dateTime.utcTime();
209
bool LocalDateTime::operator > (const LocalDateTime& dateTime) const
211
return utcTime() > dateTime.utcTime();
215
bool LocalDateTime::operator >= (const LocalDateTime& dateTime) const
217
return utcTime() >= dateTime.utcTime();
221
LocalDateTime LocalDateTime::operator + (const Timespan& span) const
223
return LocalDateTime(_dateTime.utcTime(), span.totalMicroseconds(), _tzd);
227
LocalDateTime LocalDateTime::operator - (const Timespan& span) const
229
return LocalDateTime(_dateTime.utcTime(), -span.totalMicroseconds(), _tzd);
233
Timespan LocalDateTime::operator - (const LocalDateTime& dateTime) const
235
return Timespan((utcTime() - dateTime.utcTime())/10);
239
LocalDateTime& LocalDateTime::operator += (const Timespan& span)
246
LocalDateTime& LocalDateTime::operator -= (const Timespan& span)