1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-14 19:57:17 +01:00
SqMod/vendor/POCO/Foundation/src/Timespan.cpp
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface.
Deprecated the external module API. It was creating more problems than solving.
Removed most built-in libraries in favor of system libraries for easier maintenance.
Cleaned and secured code with help from static analyzers.
2021-01-30 08:51:39 +02:00

146 lines
2.6 KiB
C++

//
// Timespan.cpp
//
// Library: Foundation
// Package: DateTime
// Module: Timespan
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Timespan.h"
#include <algorithm>
namespace Poco {
const Timespan::TimeDiff Timespan::MILLISECONDS = 1000;
const Timespan::TimeDiff Timespan::SECONDS = 1000*Timespan::MILLISECONDS;
const Timespan::TimeDiff Timespan::MINUTES = 60*Timespan::SECONDS;
const Timespan::TimeDiff Timespan::HOURS = 60*Timespan::MINUTES;
const Timespan::TimeDiff Timespan::DAYS = 24*Timespan::HOURS;
Timespan::Timespan():
_span(0)
{
}
Timespan::Timespan(TimeDiff microSeconds):
_span(microSeconds)
{
}
Timespan::Timespan(long seconds, long microSeconds):
_span(TimeDiff(seconds)*SECONDS + microSeconds)
{
}
Timespan::Timespan(int days, int hours, int minutes, int seconds, int microSeconds):
_span(TimeDiff(microSeconds) + TimeDiff(seconds)*SECONDS + TimeDiff(minutes)*MINUTES + TimeDiff(hours)*HOURS + TimeDiff(days)*DAYS)
{
}
Timespan::Timespan(const Timespan& timespan):
_span(timespan._span)
{
}
Timespan& Timespan::operator = (const Timespan& timespan)
{
_span = timespan._span;
return *this;
}
Timespan& Timespan::operator = (TimeDiff microSeconds)
{
_span = microSeconds;
return *this;
}
Timespan& Timespan::assign(int days, int hours, int minutes, int seconds, int microSeconds)
{
_span = TimeDiff(microSeconds) + TimeDiff(seconds)*SECONDS + TimeDiff(minutes)*MINUTES + TimeDiff(hours)*HOURS + TimeDiff(days)*DAYS;
return *this;
}
Timespan& Timespan::assign(long seconds, long microSeconds)
{
_span = TimeDiff(seconds)*SECONDS + TimeDiff(microSeconds);
return *this;
}
void Timespan::swap(Timespan& timespan)
{
std::swap(_span, timespan._span);
}
Timespan Timespan::operator + (const Timespan& d) const
{
return Timespan(_span + d._span);
}
Timespan Timespan::operator - (const Timespan& d) const
{
return Timespan(_span - d._span);
}
Timespan& Timespan::operator += (const Timespan& d)
{
_span += d._span;
return *this;
}
Timespan& Timespan::operator -= (const Timespan& d)
{
_span -= d._span;
return *this;
}
Timespan Timespan::operator + (TimeDiff microSeconds) const
{
return Timespan(_span + microSeconds);
}
Timespan Timespan::operator - (TimeDiff microSeconds) const
{
return Timespan(_span - microSeconds);
}
Timespan& Timespan::operator += (TimeDiff microSeconds)
{
_span += microSeconds;
return *this;
}
Timespan& Timespan::operator -= (TimeDiff microSeconds)
{
_span -= microSeconds;
return *this;
}
} // namespace Poco