2 Copyright (C) 2023 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/>.
24 #include <dcp/certificate.h>
25 #include <boost/optional.hpp>
32 using std::shared_ptr;
34 using boost::optional;
38 check_kdm_and_certificate_validity_periods(
39 string const& cinema_name,
40 string const& screen_name,
41 dcp::Certificate const& recipient,
42 dcp::LocalTime kdm_from,
46 auto overlaps = [](dcp::LocalTime from_a, dcp::LocalTime to_a, dcp::LocalTime from_b, dcp::LocalTime to_b) {
47 return std::max(from_a, from_b) < std::min(to_a, to_b);
50 auto contains = [](dcp::LocalTime bigger_from, dcp::LocalTime bigger_to, dcp::LocalTime smaller_from, dcp::LocalTime smaller_to) {
51 return bigger_from <= smaller_from && bigger_to >= smaller_to;
54 KDMCertificatePeriod period(
57 recipient.not_before(),
61 if (contains(recipient.not_before(), recipient.not_after(), kdm_from, kdm_to)) {
62 period.overlap = KDMCertificateOverlap::KDM_WITHIN_CERTIFICATE;
66 if (overlaps(recipient.not_before(), recipient.not_after(), kdm_from, kdm_to)) {
67 /* The KDM overlaps the certificate validity: maybe not the end of the world */
68 period.overlap = KDMCertificateOverlap::KDM_OVERLAPS_CERTIFICATE;
71 /* The KDM validity is totally outside the certificate validity: bad news */
72 period.overlap = KDMCertificateOverlap::KDM_OUTSIDE_CERTIFICATE;