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

Feature/sub hourly #85

Merged
merged 8 commits into from
Dec 8, 2023
Merged

Feature/sub hourly #85

merged 8 commits into from
Dec 8, 2023

Conversation

danovaro
Copy link
Member

No description provided.

@FussyDuck
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov-commenter
Copy link

codecov-commenter commented Oct 27, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (721b7a0) 62.80% compared to head (c041bfa) 63.03%.
Report is 2 commits behind head on develop.

Files Patch % Lines
src/eckit/types/Time.cc 93.54% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #85      +/-   ##
===========================================
+ Coverage    62.80%   63.03%   +0.22%     
===========================================
  Files          790      791       +1     
  Lines        45196    45338     +142     
===========================================
+ Hits         28386    28577     +191     
+ Misses       16810    16761      -49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@pmaciel pmaciel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes here are all an improvement 😄 👍

I suggest in the future (because now isn't the right time) to move this class downstream, as it is not at the righ place on the pgen/mars-client stack (to my knowledge); it isn't "down enough", it is part of, and contains, MARS-specific interpretation of time, and should exist at the language parsing level instead.

if (seconds >= 86400 || seconds < 0) {
std::string msg = "Time in seconds must be positive and cannot exceed 86400, seconds: ";
if ((seconds >= 86400 && !extended) || seconds < 0) {
std::string msg = "Time in seconds must be positive and less than 86400 seconds (24h): ";
Translator<long, std::string> t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert Translator<long, std::string> to std::to_string

@@ -8,6 +8,9 @@
* does it submit to any jurisdiction.
*/

#include <regex>
#include <cmath>

#include "eckit/eckit.h"

#include "eckit/persist/DumpLoad.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove #include "eckit/utils/Tokenizer.h"

err = true;
break;
Time::Time(const std::string& s, bool extended) {
long ss = 0, mm = 0, hh = 0, dd = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declarations should be one-per-line

@@ -32,9 +32,9 @@ typedef double Second;
class Time {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modernise
typedef double Second
to
using Second = double;

Time(const std::string&);
Time(long, long, long, bool extended = false);
Time(long seconds = 0, bool extended = false);
Time(const std::string&, bool extended = false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the arguments names (since they are not deducible by the type).

To be consistent, it's also missing one constructor
Time(long minutes, long seconds, bool extended = false);

std::string msg = "Wrong input for time: ";
Translator<long, std::string> t;
if (dd>0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't consistent with the check above, for ss<86400. (eg, line 35 but there are more). If the class isn't to support days, and it also doesn't have and accessor for it, this should actually fail (or, remove the checks and support it)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this printing of time as string is repeated in multiple places -- ideally, these places should be replaced with a operator std::string (that you already have)

@@ -27,80 +30,98 @@ inline void printTime(std::ostream& s, long n) {
s << n;
}

Time::Time(long seconds) :
Time::Time(long seconds, bool extended) :
seconds_(seconds) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires a seconds_(static_cast(seconds))

Copy link
Contributor

@simondsmart simondsmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Noting Pedro's comments as well. Please lightly tidy up, then merge.

EXPECT(Time(0,3,0) == Time("3M"));
EXPECT(Time(0,3,0) == Time("180s"));

EXPECT(Time(1,23,45) == Time("1h23m45s"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ought to have tests that cover such things as 1h2m3s (I.e. where mins and secs are single digit, including following previous terms).

seconds_(hh * 3600 + mm * 60 + ss) {
if (hh >= 24 || mm >= 60 || ss >= 60 || hh < 0 || mm < 0 || ss < 0) {
if (mm >= 60 || ss >= 60 || (!extended && (hh >= 24 || hh < 0 || mm < 0 || ss < 0))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IS there a reason we can't don't support 61 minutes, or 61 seconds, and lroll them into larger time units, given that we do that with hours here?

@danovaro danovaro merged commit 3ca78c4 into develop Dec 8, 2023
116 of 128 checks passed
@danovaro danovaro deleted the feature/subHourly branch December 8, 2023 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants