You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/06/01 11:40:59 UTC

[GitHub] [nifi-minifi-cpp] lordgamez commented on a diff in pull request #1335: MINIFICPP-1809: custom Cron(quartz syntax) implementation and cron tests

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


##########
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:
   It may be better only declaring one member per line as per suggested by the [core guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es10-declare-one-name-only-per-declaration)



##########
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:
   nitpick: as they are only used once, I'm not sure it's necessary to use `using` here, also if you do it would be more readable in separate lines



-- 
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: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org