Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces magic numbers with compile-time variables #159

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/eckit/log/RotationTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class RotationOutputStream {

std::ostream& rotout() {

time_t now = ::time(nullptr) / 86400;
time_t now = ::time(nullptr) / Time::secondsInDay;

if (now != lastTime_ || last_ == nullptr) {

Expand Down
8 changes: 8 additions & 0 deletions src/eckit/types/Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#ifndef eckit_Time_h
#define eckit_Time_h

#include <cstdint>

#include "eckit/exception/Exceptions.h"
#include "eckit/persist/Bless.h"

Expand All @@ -31,6 +33,12 @@ using Second = double;

class Time {

public: // types
static constexpr std::uint64_t secondsInMinute = 60;
static constexpr std::uint64_t secondsInHour = 60 * secondsInMinute; // 3600
static constexpr std::uint64_t secondsInDay = 24 * secondsInHour; // 86400
static constexpr std::uint64_t secondsInWeek = 7 * secondsInDay; // 604800

public: // methods
Time(long hours, long minutes, long seconds, bool extended = false);
Time(long seconds = 0, bool extended = false);
Expand Down
Loading