Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
xanthospap committed Oct 21, 2024
1 parent 521fd55 commit 5fab73c
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 140 deletions.
300 changes: 178 additions & 122 deletions include/tpdate.hpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/lib/tpdateutc.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "tpdate.hpp"
#include <cstdlib>

dso::TwoPartDate
dso::TwoPartDateUTC::operator-(const dso::TwoPartDateUTC &d) const noexcept {
int days = imjd() - d.imjd();
double sec = seconds() - d.seconds();
FDOUBLE sec = seconds().seconds() - d.seconds().seconds();
if (!days) {
/*return dso::TwoPartDate(days, sec);*/
;
Expand Down
2 changes: 1 addition & 1 deletion test/should_not_compile/fractional_seconds_op_equal.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "dtfund.hpp"
#include "calendar.hpp"

using namespace dso;

Expand Down
2 changes: 1 addition & 1 deletion test/should_not_compile/fractional_seconds_op_greater.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "dtfund.hpp"
#include "calendar.hpp"

using namespace dso;

Expand Down
3 changes: 1 addition & 2 deletions test/should_not_compile/fund_type_op_plusequal.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "dtfund.hpp"
#include <cassert>
#include "calendar.hpp"

int main() {

Expand Down
2 changes: 1 addition & 1 deletion test/sofa/epj_date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main() {
/* do the same with SOFA */
double epj_sofa;
{
const double jd1 = d.seconds() / SEC_PER_DAY;
const double jd1 = d.seconds().seconds() / SEC_PER_DAY;
const double jd2 = d.imjd() + MJD0_JD;
const double sje = iauEpj(jd2, jd1);
double jd11, jd21;
Expand Down
8 changes: 4 additions & 4 deletions test/unit_tests/dread3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ int main() {
/* reach 23:59:59.999 999 999 */
err = 0e0;
for (int i = 0; i < (int)(1e9) - 1; i++)
tai.add_seconds(1e-9, err);
tai.add_seconds(FractionalSeconds(1e-9), err);
std::strcat(reset_buffer(buf1), leap_insertion_dates_str[it]);
std::strcat(buf1, s_2359599);
d1 = from_char<YMDFormat::YYYYMMDD, HMSFormat::HHMMSSF>(buf1);
assert(fequal(d1, tai));
assert(equal_within_ulps(d1.seconds(), tai.seconds(), 1));

/* one more nanosec will take to the next day */
tai.add_seconds(1e-9, err);
tai.add_seconds(FractionalSeconds(1e-9), err);
assert(tai.imjd() == d1.imjd() + 1);
d1 = TwoPartDate(modified_julian_day(d).as_underlying_type() + 1,
FractionalSeconds(0e0));
Expand All @@ -170,15 +170,15 @@ int main() {
/* reach 23:59:59.999 999 999 */
err = 0e0;
for (int i = 0; i < (int)(1e9) - 1; i++)
utc.add_seconds(1e-9, err);
utc.add_seconds(FractionalSeconds(1e-9), err);
std::strcat(reset_buffer(buf1), leap_insertion_dates_str[it]);
std::strcat(buf1, s_2359599);
d1 = from_utc_char<YMDFormat::YYYYMMDD, HMSFormat::HHMMSSF>(buf1);
assert(fequal(d1, utc));
assert(equal_within_ulps(d1.seconds(), utc.seconds(), 1));

/* one more nanosec will take to next second, NOT the next day */
utc.add_seconds(1e-9, err);
utc.add_seconds(FractionalSeconds(1e-9), err);
assert(utc.imjd() == d1.imjd());
/* equal to YYYY-MM-DD 23:59:60 */
std::strcat(reset_buffer(buf1), leap_insertion_dates_str[it]);
Expand Down
16 changes: 8 additions & 8 deletions test/unit_tests/tpdate_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ int main() {
assert(td1.imjd() - 1 == d1.imjd().as_underlying_type());
assert(td1.seconds() == 0e0);

td1 = datetime<nanoseconds>(year(2023), month(10), day_of_month(24),
nanoseconds(0));
td1 = TwoPartDate(datetime<nanoseconds>(year(2023), month(10),
day_of_month(24), nanoseconds(0)));
for (int i = 0; i < 2 * 86400; i++) {
td1.add_seconds(FractionalSeconds(1e0));
}
assert(td1.imjd() - 2 == d1.imjd().as_underlying_type());
assert(td1.seconds() == 0e0);

td1 = datetime<nanoseconds>(year(2023), month(10), day_of_month(24),
nanoseconds(0));
td1 = TwoPartDate(datetime<nanoseconds>(year(2023), month(10),
day_of_month(24), nanoseconds(0)));
for (int i = 0; i < 86400; i++) {
td1.add_seconds(FractionalSeconds(-1e0));
}
assert(td1.imjd() + 1 == d1.imjd().as_underlying_type());
assert(td1.seconds() == 0e0);

td1 = datetime<nanoseconds>(year(2023), month(10), day_of_month(24),
nanoseconds(0));
td1 = TwoPartDate(datetime<nanoseconds>(year(2023), month(10),
day_of_month(24), nanoseconds(0)));
for (int i = 0; i < 2 * 86400; i++) {
td1.add_seconds(FractionalSeconds(-1e0));
}
assert(td1.imjd() + 2 == d1.imjd().as_underlying_type());
assert(td1.seconds() == 0e0);

td1 = datetime<nanoseconds>(year(2023), month(10), day_of_month(24),
nanoseconds(0));
td1 = TwoPartDate(datetime<nanoseconds>(year(2023), month(10),
day_of_month(24), nanoseconds(0)));
for (int i = 0; i < 86400; i++) {
td1.add_seconds(FractionalSeconds(2e0));
td1.add_seconds(FractionalSeconds(-1e0));
Expand Down

0 comments on commit 5fab73c

Please sign in to comment.