martinzink commented on code in PR #1335:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1335#discussion_r886867467


##########
libminifi/include/utils/Cron.h:
##########
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <exception>
+#include <string>
+#include <chrono>
+#include <optional>
+#include <memory>
+#include <utility>
+#include "date/tz.h"
+
+namespace org::apache::nifi::minifi::utils {
+class BadCronExpression : public std::exception {
+ public:
+  explicit BadCronExpression(std::string msg) : msg_(std::move(msg)) {}
+
+  [[nodiscard]] const char* what() const noexcept override { return 
(msg_.c_str()); }
+
+ private:
+  std::string msg_;
+};
+
+class CronField {
+ public:
+  virtual ~CronField() = default;
+
+  [[nodiscard]] virtual bool matches(date::local_seconds time_point) const = 0;
+};
+
+class Cron {
+ public:
+  explicit Cron(const std::string& expression);
+  Cron(Cron&& cron) = default;
+
+  [[nodiscard]] std::optional<date::local_seconds> 
calculateNextTrigger(date::local_seconds start) const;
+
+  std::unique_ptr<CronField> second_, minute_, hour_, day_, month_, 
day_of_week_, year_;

Review Comment:
   good idea, I've changed it in 
https://github.com/apache/nifi-minifi-cpp/pull/1335/commits/474cb1571b81b27a5e9871a63fea53cf30428e1c



##########
libminifi/src/utils/Cron.cpp:
##########
@@ -0,0 +1,507 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/Cron.h"
+#include <charconv>
+#include "utils/TimeUtil.h"
+#include "utils/StringUtils.h"
+#include "date/date.h"
+
+using namespace std::literals::chrono_literals;
+
+using std::chrono::seconds;
+using std::chrono::minutes;
+using std::chrono::hours;
+using std::chrono::days;
+
+// TODO(C++20): move to std::chrono when calendar is fully supported
+using date::local_seconds;
+using date::day;
+using date::weekday;
+using date::month;
+using date::year;
+using date::year_month_day;
+using date::last;
+using date::local_days;
+using date::from_stream;
+using date::make_time;
+
+using date::Friday; using date::Saturday; using date::Sunday;

Review Comment:
   I wanted to list clearly what are we using from date and what from 
std::chrono.
   But I agree its more readable to separate them. 
https://github.com/apache/nifi-minifi-cpp/pull/1335/commits/474cb1571b81b27a5e9871a63fea53cf30428e1c
 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to