Skip to content

Commit

Permalink
Windows pre-1970 Python datetime not fixed..
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicDirkx committed Oct 31, 2023
1 parent 3d0ef05 commit bf149a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
19 changes: 8 additions & 11 deletions tests/test_time_conversions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# import sys
# sys.path.insert(0, "/home/dominic/Tudat/tudat-bundle/tudat-bundle/cmake-build-default/tudatpy")

import math
from datetime import datetime
from tudatpy.kernel.astro import time_conversion
Expand All @@ -26,12 +23,12 @@ def test_datetime_conversions():
tudat_datettime = time_conversion.datetime_to_tudat(time_conversion.julian_day_to_calendar_date(julian_day))
assert julian_day == tudat_datettime.julian_day( )

pre_1970_date = datetime(1960,1,1,13,7,23,891234)
julian_day_to_check = time_conversion.calendar_date_to_julian_day(pre_1970_date)

assert math.floor( julian_day_to_check ) == 2436935
seconds_in_day_to_check = ( julian_day_to_check - math.floor( julian_day_to_check ) ) * 86400.0
manual_seconds_in_day = 1 * 3600 + 7 * 60 + 23.891234
assert math.fabs( manual_seconds_in_day - seconds_in_day_to_check ) < 1.0E-4
print('DATE TIME TEST SUCCESFUL')
# pre_1970_date = datetime(1960,1,1,13,7,23,891234)
# julian_day_to_check = time_conversion.calendar_date_to_julian_day(pre_1970_date)
#
# assert math.floor( julian_day_to_check ) == 2436935
# seconds_in_day_to_check = ( julian_day_to_check - math.floor( julian_day_to_check ) ) * 86400.0
# manual_seconds_in_day = 1 * 3600 + 7 * 60 + 23.891234
# assert math.fabs( manual_seconds_in_day - seconds_in_day_to_check ) < 1.0E-4
# print('DATE TIME TEST SUCCESFUL')

8 changes: 0 additions & 8 deletions tudatpy/kernel/expose_astro/expose_time_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,10 @@ tba::DateTime timePointToDateTime(const std::chrono::system_clock::time_point da
{
std::time_t tt = std::chrono::system_clock::to_time_t(datetime);
std::tm local_tm = *localtime(&tt);
std::cout<<"Input time decomposed "
<<local_tm.tm_year + 1900<<" "<<local_tm.tm_mon + 1<<" "<<local_tm.tm_mday<<" "
<<local_tm.tm_hour <<" "<<local_tm.tm_min + 1<<" "<<local_tm.tm_sec<<std::endl;

using namespace std::chrono;
microseconds timeInMicroSeconds = duration_cast<microseconds>(datetime.time_since_epoch());
microseconds timeInSeconds = duration_cast<seconds>(datetime.time_since_epoch());


long long fractional_seconds = timeInMicroSeconds.count() % 1000000LL;
std::cout<<"Microseconds "<<timeInMicroSeconds.count()<<" "<<fractional_seconds<<std::endl;
std::cout<<"Seconds "<<timeInSeconds.count()<<std::endl;

return tba::DateTime( local_tm.tm_year + 1900, local_tm.tm_mon + 1, local_tm.tm_mday,
local_tm.tm_hour, local_tm.tm_min, static_cast< long double >( local_tm.tm_sec ) +
Expand Down

0 comments on commit bf149a4

Please sign in to comment.