1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "base/datetime.hpp"
4 #include "base/datetime-ti.cpp"
5 #include "base/utility.hpp"
6 #include "base/primitivetype.hpp"
8 using namespace icinga;
10 REGISTER_TYPE_WITH_PROTOTYPE(DateTime, DateTime::GetPrototype());
12 DateTime::DateTime(double value)
16 DateTime::DateTime(const std::vector<Value>& args)
19 m_Value = Utility::GetTime();
20 else if (args.size() == 3 || args.size() == 6) {
22 tms.tm_year = args[0] - 1900;
23 tms.tm_mon = args[1] - 1;
24 tms.tm_mday = args[2];
26 if (args.size() == 6) {
27 tms.tm_hour = args[3];
38 m_Value = mktime(&tms);
39 } else if (args.size() == 1)
42 BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid number of arguments for the DateTime constructor."));
45 double DateTime::GetValue() const
50 String DateTime::Format(const String& format) const
52 return Utility::FormatDateTime(format.CStr(), m_Value);
55 String DateTime::ToString() const
57 return Format("%Y-%m-%d %H:%M:%S %z");