~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Foundation/src/LocalDateTime.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// LocalDateTime.cpp
 
3
//
 
4
// $Id: //poco/1.2/Foundation/src/LocalDateTime.cpp#1 $
 
5
//
 
6
// Library: Foundation
 
7
// Package: DateTime
 
8
// Module:  LocalDateTime
 
9
//
 
10
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
 
11
// and Contributors.
 
12
//
 
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:
 
19
// 
 
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.
 
26
// 
 
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.
 
34
//
 
35
 
 
36
 
 
37
#include "Poco/LocalDateTime.h"
 
38
#include "Poco/Timezone.h"
 
39
#include "Poco/Timespan.h"
 
40
#include <algorithm>
 
41
 
 
42
 
 
43
namespace Poco {
 
44
 
 
45
 
 
46
LocalDateTime::LocalDateTime():
 
47
        _tzd(Timezone::tzd())
 
48
{
 
49
        _dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
50
}
 
51
 
 
52
 
 
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),
 
55
        _tzd(Timezone::tzd())
 
56
{
 
57
}
 
58
 
 
59
 
 
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),
 
62
        _tzd(tzd)
 
63
{
 
64
}
 
65
 
 
66
 
 
67
LocalDateTime::LocalDateTime(double julianDay):
 
68
        _dateTime(julianDay),
 
69
        _tzd(Timezone::tzd())
 
70
{
 
71
        _dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
72
}
 
73
 
 
74
 
 
75
LocalDateTime::LocalDateTime(int tzd, double julianDay):
 
76
        _dateTime(julianDay),
 
77
        _tzd(tzd)
 
78
{
 
79
        _dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
80
}
 
81
 
 
82
 
 
83
LocalDateTime::LocalDateTime(const DateTime& dateTime):
 
84
        _dateTime(dateTime),
 
85
        _tzd(Timezone::tzd())
 
86
{
 
87
        _dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
88
}
 
89
 
 
90
 
 
91
LocalDateTime::LocalDateTime(int tzd, const DateTime& dateTime):
 
92
        _dateTime(dateTime),
 
93
        _tzd(tzd)
 
94
{
 
95
        _dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
96
}
 
97
 
 
98
 
 
99
LocalDateTime::LocalDateTime(const LocalDateTime& dateTime):
 
100
        _dateTime(dateTime._dateTime),
 
101
        _tzd(dateTime._tzd)
 
102
{
 
103
}
 
104
 
 
105
 
 
106
LocalDateTime::LocalDateTime(Timestamp::UtcTimeVal utcTime, Timestamp::TimeDiff diff, int tzd):
 
107
        _dateTime(utcTime, diff),
 
108
        _tzd(tzd)
 
109
{
 
110
}
 
111
 
 
112
        
 
113
LocalDateTime::~LocalDateTime()
 
114
{
 
115
}
 
116
 
 
117
        
 
118
LocalDateTime& LocalDateTime::operator = (const LocalDateTime& dateTime)
 
119
{
 
120
        if (&dateTime != this)
 
121
        {
 
122
                _dateTime = dateTime._dateTime;
 
123
                _tzd      = dateTime._tzd;
 
124
        }
 
125
        return *this;
 
126
}
 
127
 
 
128
 
 
129
LocalDateTime& LocalDateTime::operator = (const Timestamp& timestamp)
 
130
{
 
131
        if (timestamp != this->timestamp())
 
132
                _dateTime = timestamp;
 
133
 
 
134
        return *this;
 
135
}
 
136
 
 
137
 
 
138
LocalDateTime& LocalDateTime::operator = (double julianDay)
 
139
{
 
140
        _tzd      = Timezone::tzd();
 
141
        _dateTime = julianDay;
 
142
        _dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
143
        return *this;
 
144
}
 
145
 
 
146
        
 
147
LocalDateTime& LocalDateTime::assign(int year, int month, int day, int hour, int minute, int second, int millisecond, int microseconds)
 
148
{
 
149
        _dateTime.assign(year, month, day, hour, minute, second, millisecond, microseconds);
 
150
        _tzd = Timezone::tzd();
 
151
        return *this;
 
152
}
 
153
 
 
154
 
 
155
LocalDateTime& LocalDateTime::assign(int tzd, int year, int month, int day, int hour, int minute, int second, int millisecond, int microseconds)
 
156
{
 
157
        _dateTime.assign(year, month, day, hour, minute, second, millisecond, microseconds);
 
158
        _tzd = tzd;
 
159
        return *this;
 
160
}
 
161
 
 
162
 
 
163
LocalDateTime& LocalDateTime::assign(int tzd, double julianDay)
 
164
{
 
165
        _tzd      = tzd;
 
166
        _dateTime = julianDay;
 
167
        _dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
168
        return *this;
 
169
}
 
170
 
 
171
 
 
172
void LocalDateTime::swap(LocalDateTime& dateTime)
 
173
{
 
174
        _dateTime.swap(dateTime._dateTime);
 
175
        std::swap(_tzd, dateTime._tzd);
 
176
}
 
177
 
 
178
 
 
179
DateTime LocalDateTime::utc() const
 
180
{
 
181
        return DateTime(_dateTime.utcTime(), -((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
 
182
}
 
183
 
 
184
 
 
185
bool LocalDateTime::operator == (const LocalDateTime& dateTime) const
 
186
{
 
187
        return utcTime() == dateTime.utcTime();
 
188
}
 
189
 
 
190
 
 
191
bool LocalDateTime::operator != (const LocalDateTime& dateTime) const   
 
192
{
 
193
        return utcTime() != dateTime.utcTime();
 
194
}
 
195
 
 
196
 
 
197
bool LocalDateTime::operator <  (const LocalDateTime& dateTime) const   
 
198
{
 
199
        return utcTime() < dateTime.utcTime();
 
200
}
 
201
 
 
202
 
 
203
bool LocalDateTime::operator <= (const LocalDateTime& dateTime) const   
 
204
{
 
205
        return utcTime() <= dateTime.utcTime();
 
206
}
 
207
 
 
208
 
 
209
bool LocalDateTime::operator >  (const LocalDateTime& dateTime) const   
 
210
{
 
211
        return utcTime() > dateTime.utcTime();
 
212
}
 
213
 
 
214
 
 
215
bool LocalDateTime::operator >= (const LocalDateTime& dateTime) const   
 
216
{
 
217
        return utcTime() >= dateTime.utcTime();
 
218
}
 
219
 
 
220
 
 
221
LocalDateTime LocalDateTime::operator + (const Timespan& span) const
 
222
{
 
223
        return LocalDateTime(_dateTime.utcTime(), span.totalMicroseconds(), _tzd);      
 
224
}
 
225
 
 
226
 
 
227
LocalDateTime LocalDateTime::operator - (const Timespan& span) const
 
228
{
 
229
        return LocalDateTime(_dateTime.utcTime(), -span.totalMicroseconds(), _tzd);     
 
230
}
 
231
 
 
232
 
 
233
Timespan LocalDateTime::operator - (const LocalDateTime& dateTime) const
 
234
{
 
235
        return Timespan((utcTime() - dateTime.utcTime())/10);
 
236
}
 
237
 
 
238
 
 
239
LocalDateTime& LocalDateTime::operator += (const Timespan& span)
 
240
{
 
241
        _dateTime += span;
 
242
        return *this;
 
243
}
 
244
 
 
245
 
 
246
LocalDateTime& LocalDateTime::operator -= (const Timespan& span)
 
247
{
 
248
        _dateTime -= span;
 
249
        return *this;
 
250
}
 
251
 
 
252
 
 
253
} // namespace Poco