Skip to content

Commit 7376e74

Browse files
committed
Improve coverage for Date to Julian Day conversion
- Move conversion functions to Calendar.(h|c)pp - Remove unnecessary Cal - Add tests for the convertion
1 parent 0f3621b commit 7376e74

File tree

13 files changed

+133
-147
lines changed

13 files changed

+133
-147
lines changed

Viewer/ecflowUI/src/VRepeatAttr.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "VAttributeType.hpp"
1616
#include "VNode.hpp"
1717
#include "ecflow/attribute/RepeatRange.hpp"
18-
#include "ecflow/core/Cal.hpp"
18+
#include "ecflow/core/Calendar.hpp"
1919

2020
std::string VRepeatDateAttr::subType_("date");
2121
std::string VRepeatDateTimeAttr::subType_("datetime");
@@ -195,8 +195,8 @@ int VRepeatDateAttr::endIndex() const {
195195
if (node_ptr node = parent_->node()) {
196196
const Repeat& r = node->repeat();
197197
if (r.step() > 0) {
198-
long jStart = Cal::date_to_julian(r.start());
199-
long jEnd = Cal::date_to_julian(r.end());
198+
long jStart = ecf::calendar_date_to_julian_day(r.start());
199+
long jEnd = ecf::calendar_date_to_julian_day(r.end());
200200

201201
int index = (jEnd - jStart) / r.step();
202202
long val = jStart + index * r.step();
@@ -213,7 +213,7 @@ int VRepeatDateAttr::endIndex() const {
213213
int VRepeatDateAttr::currentIndex() const {
214214
if (node_ptr node = parent_->node()) {
215215
const Repeat& r = node->repeat();
216-
int cur = (Cal::date_to_julian(r.index_or_value()) - Cal::date_to_julian(r.start())) / r.step();
216+
int cur = (ecf::calendar_date_to_julian_day(r.index_or_value()) - ecf::calendar_date_to_julian_day(r.start())) / r.step();
217217
return cur;
218218
}
219219
return 0;
@@ -239,7 +239,7 @@ std::string VRepeatDateAttr::value(int index) const {
239239
std::stringstream ss;
240240
if (node_ptr node = parent_->node()) {
241241
const Repeat& r = node->repeat();
242-
ss << (Cal::julian_to_date(Cal::date_to_julian(r.start()) + index * r.step()));
242+
ss << (ecf::julian_day_to_calendar_date(ecf::calendar_date_to_julian_day(r.start()) + index * r.step()));
243243
}
244244

245245
return ss.str();
@@ -252,7 +252,7 @@ int VRepeatDateAttr::currentPosition() const {
252252
return -1;
253253
else if (r.value() == r.start())
254254
return 0;
255-
else if (r.value() == r.end() || Cal::date_to_julian(r.value()) + r.step() > Cal::date_to_julian(r.end()))
255+
else if (r.value() == r.end() || ecf::calendar_date_to_julian_day(r.value()) + r.step() > ecf::calendar_date_to_julian_day(r.end()))
256256
return 2;
257257
else
258258
return 1;

libs/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ set(srcs
230230
${CMAKE_BINARY_DIR}/generated/src/ecflow/core/ecflow_version.h
231231
${CMAKE_BINARY_DIR}/generated/src/ecflow/core/ecflow_source_build_dir.h
232232
core/src/ecflow/core/AssertTimer.hpp
233-
core/src/ecflow/core/Cal.hpp
234233
core/src/ecflow/core/Calendar.hpp
235234
core/src/ecflow/core/CalendarUpdateParams.hpp
236235
core/src/ecflow/core/CheckPt.hpp
@@ -279,7 +278,6 @@ set(srcs
279278
core/src/ecflow/core/exceptions/Exceptions.hpp
280279
# Core -- Sources
281280
core/src/ecflow/core/AssertTimer.cpp
282-
core/src/ecflow/core/Cal.cpp
283281
core/src/ecflow/core/Calendar.cpp
284282
core/src/ecflow/core/Child.cpp
285283
core/src/ecflow/core/Chrono.cpp

libs/attribute/src/ecflow/attribute/RepeatAttr.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <boost/date_time.hpp>
1717
#include <boost/date_time/posix_time/time_parsers.hpp>
1818

19-
#include "ecflow/core/Cal.hpp"
19+
#include "ecflow/core/Calendar.hpp"
2020
#include "ecflow/core/Converter.hpp"
2121
#include "ecflow/core/Ecf.hpp"
2222
#include "ecflow/core/Indentor.hpp"
@@ -260,7 +260,7 @@ void RepeatDate::update_repeat_genvar_value() const {
260260
dow_.set_value(ecf::convert_to<std::string>(day_of_week));
261261

262262
long last_value = last_valid_value();
263-
long julian = Cal::date_to_julian(last_value);
263+
long julian = ecf::calendar_date_to_julian_day(last_value);
264264
julian_.set_value(ecf::convert_to<std::string>(julian));
265265
}
266266
catch (std::exception& e) {
@@ -305,16 +305,16 @@ long RepeatDate::valid_value(long value) const {
305305

306306
long RepeatDate::last_valid_value_minus(int val) const {
307307
long last_value = last_valid_value();
308-
long julian = Cal::date_to_julian(last_value);
308+
long julian = ecf::calendar_date_to_julian_day(last_value);
309309
julian -= val;
310-
return Cal::julian_to_date(julian);
310+
return ecf::julian_day_to_calendar_date(julian);
311311
}
312312

313313
long RepeatDate::last_valid_value_plus(int val) const {
314314
long last_value = last_valid_value();
315-
long julian = Cal::date_to_julian(last_value);
315+
long julian = ecf::calendar_date_to_julian_day(last_value);
316316
julian += val;
317-
return Cal::julian_to_date(julian);
317+
return ecf::julian_day_to_calendar_date(julian);
318318
}
319319

320320
void RepeatDate::reset() {
@@ -386,9 +386,9 @@ std::string RepeatDate::value_as_string(int index) const {
386386
std::string RepeatDate::next_value_as_string() const {
387387
long val = last_valid_value();
388388

389-
long julian = Cal::date_to_julian(val);
389+
long julian = ecf::calendar_date_to_julian_day(val);
390390
julian += delta_;
391-
val = Cal::julian_to_date(julian);
391+
val = ecf::julian_day_to_calendar_date(julian);
392392

393393
try {
394394
return ecf::convert_to<std::string>(valid_value(val));
@@ -401,9 +401,9 @@ std::string RepeatDate::next_value_as_string() const {
401401
std::string RepeatDate::prev_value_as_string() const {
402402
long val = last_valid_value();
403403

404-
long julian = Cal::date_to_julian(val);
404+
long julian = ecf::calendar_date_to_julian_day(val);
405405
julian -= delta_;
406-
val = Cal::julian_to_date(julian);
406+
val = ecf::julian_day_to_calendar_date(julian);
407407

408408
try {
409409
return ecf::convert_to<std::string>(valid_value(val));
@@ -414,9 +414,9 @@ std::string RepeatDate::prev_value_as_string() const {
414414
}
415415

416416
void RepeatDate::increment() {
417-
long julian = Cal::date_to_julian(value_);
417+
long julian = ecf::calendar_date_to_julian_day(value_);
418418
julian += delta_;
419-
set_value(Cal::julian_to_date(julian));
419+
set_value(ecf::julian_day_to_calendar_date(julian));
420420
}
421421

422422
void RepeatDate::change(const std::string& newdate) {
@@ -469,8 +469,8 @@ void RepeatDate::changeValue(long the_new_date) {
469469
}
470470

471471
// Check new value is in step. ECFLOW-325 repeat date 7
472-
long julian_new_date = Cal::date_to_julian(the_new_date);
473-
long julian_start = Cal::date_to_julian(start_);
472+
long julian_new_date = ecf::calendar_date_to_julian_day(the_new_date);
473+
long julian_start = ecf::calendar_date_to_julian_day(start_);
474474
long diff = julian_new_date - julian_start;
475475
if (diff % delta_ != 0) {
476476
std::stringstream ss;
@@ -914,7 +914,7 @@ void RepeatDateList::update_repeat_genvar_value() const {
914914
dow_.set_value(ecf::convert_to<std::string>(day_of_week));
915915

916916
long last_value = last_valid_value();
917-
long julian = Cal::date_to_julian(last_value);
917+
long julian = ecf::calendar_date_to_julian_day(last_value);
918918
julian_.set_value(ecf::convert_to<std::string>(julian));
919919
}
920920
catch (std::exception& e) {
@@ -1001,19 +1001,19 @@ long RepeatDateList::last_valid_value_minus(int val) const {
10011001
if (last_value == 0)
10021002
return 0;
10031003

1004-
long julian = Cal::date_to_julian(last_value);
1004+
long julian = ecf::calendar_date_to_julian_day(last_value);
10051005
julian -= val;
1006-
return Cal::julian_to_date(julian);
1006+
return ecf::julian_day_to_calendar_date(julian);
10071007
}
10081008

10091009
long RepeatDateList::last_valid_value_plus(int val) const {
10101010
long last_value = last_valid_value();
10111011
if (last_value == 0)
10121012
return 0;
10131013

1014-
long julian = Cal::date_to_julian(last_value);
1014+
long julian = ecf::calendar_date_to_julian_day(last_value);
10151015
julian += val;
1016-
return Cal::julian_to_date(julian);
1016+
return ecf::julian_day_to_calendar_date(julian);
10171017
}
10181018

10191019
void RepeatDateList::setToLastValue() {

libs/attribute/src/ecflow/attribute/RepeatAttr.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <vector>
3030

3131
#include "ecflow/attribute/Variable.hpp"
32-
#include "ecflow/core/Cal.hpp"
3332
#include "ecflow/core/Chrono.hpp"
3433

3534
/////////////////////////////////////////////////////////////////////////

libs/attribute/src/ecflow/attribute/RepeatRange.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define ecflow_attribute_RepeatRange_HPP
1313

1414
#include "ecflow/attribute/RepeatAttr.hpp"
15+
#include "ecflow/core/Calendar.hpp"
1516

1617
namespace ecf {
1718

@@ -54,25 +55,25 @@ struct Range<RepeatDate>
5455

5556
iterator begin() const { return 0; }
5657
iterator end() const {
57-
int i = Cal::date_to_julian(r_.start());
58-
int j = Cal::date_to_julian(r_.end());
58+
int i = ecf::calendar_date_to_julian_day(r_.start());
59+
int j = ecf::calendar_date_to_julian_day(r_.end());
5960
int s = r_.step();
6061
int d = (j - i) + 1;
6162
return (d / s) + ((d % s == 0) ? 0 : 1);
6263
}
6364
iterator current_index() const {
64-
auto i = Cal::date_to_julian(r_.start());
65+
auto i = ecf::calendar_date_to_julian_day(r_.start());
6566
auto s = r_.step();
66-
auto v = Cal::date_to_julian(r_.value());
67+
auto v = ecf::calendar_date_to_julian_day(r_.value());
6768
auto idx = (v - i) / s;
6869
return idx;
6970
}
7071

7172
value_type current_value() const { return r_.value(); }
7273

7374
value_type at(iterator i) const {
74-
int j = Cal::date_to_julian(r_.start());
75-
return Cal::julian_to_date(j + i * r_.step());
75+
int j = ecf::calendar_date_to_julian_day(r_.start());
76+
return ecf::julian_day_to_calendar_date(j + i * r_.step());
7677
}
7778

7879
size_type size() const { return end() - begin(); }

libs/attribute/test/TestRepeat.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <boost/test/unit_test.hpp>
1515

1616
#include "ecflow/attribute/RepeatAttr.hpp"
17-
#include "ecflow/core/Cal.hpp"
17+
#include "ecflow/core/Calendar.hpp"
1818
#include "ecflow/core/Converter.hpp"
1919
#include "ecflow/test/scaffold/Naming.hpp"
2020

@@ -530,7 +530,7 @@ BOOST_AUTO_TEST_CASE(generated_variables) {
530530
{
531531
const Variable& var = rep.find_gen_variable("YMD_JULIAN");
532532
BOOST_CHECK_MESSAGE(!var.empty(), "Did not find generated variable YMD_JULIAN");
533-
std::string expected = ecf::convert_to<std::string>(Cal::date_to_julian(20090916));
533+
std::string expected = ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20090916));
534534
BOOST_CHECK_MESSAGE(var.theValue() == expected, "expected " << expected << " but found " << var.theValue());
535535
}
536536
}
@@ -597,13 +597,13 @@ BOOST_AUTO_TEST_CASE(more_generated_variables) {
597597
expected_day_of_week.emplace_back("5");
598598

599599
std::vector<std::string> expected_julian;
600-
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20161231)));
601-
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170101)));
602-
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170102)));
603-
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170103)));
604-
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170104)));
605-
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170105)));
606-
expected_julian.push_back(ecf::convert_to<std::string>(Cal::date_to_julian(20170106)));
600+
expected_julian.push_back(ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20161231)));
601+
expected_julian.push_back(ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20170101)));
602+
expected_julian.push_back(ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20170102)));
603+
expected_julian.push_back(ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20170103)));
604+
expected_julian.push_back(ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20170104)));
605+
expected_julian.push_back(ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20170105)));
606+
expected_julian.push_back(ecf::convert_to<std::string>(ecf::calendar_date_to_julian_day(20170106)));
607607

608608
for (int i = 0; i < 7; i++) {
609609

libs/core/src/ecflow/core/Cal.cpp

-71
This file was deleted.

libs/core/src/ecflow/core/Cal.hpp

-26
This file was deleted.

0 commit comments

Comments
 (0)