2 Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "dcpomatic_assert.h"
23 #include "rough_duration.h"
24 #include <dcp/raw_convert.h>
25 #include <dcp/warnings.h>
26 LIBDCP_DISABLE_WARNINGS
27 #include <libxml++/libxml++.h>
28 LIBDCP_ENABLE_WARNINGS
34 RoughDuration::RoughDuration (cxml::ConstNodePtr node)
35 : duration(dcp::raw_convert<int>(node->content()))
37 auto const unit_name = node->string_attribute("unit");
38 if (unit_name == "days") {
40 } else if (unit_name == "weeks") {
42 } else if (unit_name == "months") {
44 } else if (unit_name == "years") {
47 DCPOMATIC_ASSERT (false);
53 RoughDuration::as_xml (xmlpp::Element* node) const
55 node->add_child_text(dcp::raw_convert<string>(duration));
59 node->set_attribute("unit", "days");
62 node->set_attribute("unit", "weeks");
65 node->set_attribute("unit", "months");
68 node->set_attribute("unit", "years");
75 operator== (RoughDuration const& a, RoughDuration const& b)
77 return a.duration == b.duration && a.unit == b.unit;