icinga2/lib/base/datetime.cpp

60 lines
1.3 KiB
C++
Raw Permalink Normal View History

Replace all existing copyright headers with `SPDX` headers I've used the following command to replace the original copyright header lines in a C-style comment block: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` For files that use shell-style comments (#) like CMakeLists.txt, I've used this command: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ``` And for SQL files: ``` $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + $ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} + ```
2026-01-27 09:06:40 -05:00
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "base/datetime.hpp"
2018-01-18 07:50:38 -05:00
#include "base/datetime-ti.cpp"
#include "base/utility.hpp"
#include "base/primitivetype.hpp"
using namespace icinga;
REGISTER_TYPE_WITH_PROTOTYPE(DateTime, DateTime::GetPrototype());
DateTime::DateTime(double value)
: m_Value(value)
{ }
DateTime::DateTime(const std::vector<Value>& args)
{
if (args.empty())
m_Value = Utility::GetTime();
else if (args.size() == 3 || args.size() == 6) {
struct tm tms;
tms.tm_year = args[0] - 1900;
tms.tm_mon = args[1] - 1;
tms.tm_mday = args[2];
if (args.size() == 6) {
tms.tm_hour = args[3];
tms.tm_min = args[4];
tms.tm_sec = args[5];
} else {
tms.tm_hour = 0;
tms.tm_min = 0;
tms.tm_sec = 0;
}
tms.tm_isdst = -1;
m_Value = Utility::TmToTimestamp(&tms);
} else if (args.size() == 1)
m_Value = args[0];
else
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid number of arguments for the DateTime constructor."));
}
double DateTime::GetValue() const
{
return m_Value;
}
String DateTime::Format(const String& format) const
{
return Utility::FormatDateTime(format.CStr(), m_Value);
}
String DateTime::ToString() const
{
return Format("%Y-%m-%d %H:%M:%S %z");
}