Fix time parsing in KDM CLI to be a bit more lenient.
authorCarl Hetherington <cth@carlh.net>
Sat, 16 Dec 2023 19:19:18 +0000 (20:19 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 16 Dec 2023 19:19:18 +0000 (20:19 +0100)
src/lib/kdm_cli.cc

index 1129130421c29c1427fd6d5192155962a0f29943..1ad96192873eaccb3d567c0a4349737211a5e408 100644 (file)
@@ -425,6 +425,22 @@ dump_dkdm_group (shared_ptr<DKDMGroup> group, int indent, std::function<void (st
 }
 
 
+static
+dcp::LocalTime
+time_from_string(string time)
+{
+       if (time == "now") {
+               return {};
+       }
+
+       if (time.length() > 10 && time[10] == ' ') {
+               time[10] = 'T';
+       }
+
+       return dcp::LocalTime(time);
+}
+
+
 optional<string>
 kdm_cli (int argc, char* argv[], std::function<void (string)> out)
 try
@@ -502,11 +518,7 @@ try
                        container_name_format = dcp::NameFormat (optarg);
                        break;
                case 'f':
-                       if (string(optarg) == "now") {
-                               valid_from = dcp::LocalTime();
-                       } else {
-                               valid_from = dcp::LocalTime(optarg);
-                       }
+                       valid_from = time_from_string(optarg);
                        break;
                case 't':
                        valid_to = dcp::LocalTime(optarg);