53 #include <wx/datetime.h>
67 wxTimeSpan ts((wxLongLong(m_span)));
84 m_pDateTime =
new wxDateTime(wxDateTime::Now());
90 m_pDateTime =
new wxDateTime(*DateTime.m_pDateTime);
96 m_pDateTime =
new wxDateTime(JDN);
102 m_pDateTime =
new wxDateTime(wxDateTime::Now());
110 m_pDateTime =
new wxDateTime(Hour, Minute, Second, Millisec);
116 m_pDateTime =
new wxDateTime(Day, (wxDateTime::Month)
Month,
Year, Hour, Minute, Second, Millisec);
133 m_pDateTime->Set(DateTime.m_pDateTime->GetTm());
141 m_pDateTime->Set(JDN);
152 if( ISODate.
Length() >= 10 && ISODate[4] ==
'-' && ISODate[7] ==
'-' )
167 m_pDateTime->Set(Hour, Minute, Second, Millisec);
175 m_pDateTime->Set(Day, (wxDateTime::Month)
Month,
Year, Hour, Minute, Second, Millisec);
183 m_pDateTime->SetMillisecond(Value);
191 m_pDateTime->SetSecond(Value);
199 m_pDateTime->SetMinute(Value);
207 m_pDateTime->SetHour(Value);
214 m_pDateTime->ResetTime();
216 Value = fmod(Value, 24.0);
if( Value < 0.0 ) Value += 24.0;
218 m_pDateTime->SetHour ((wxDateTime::wxDateTime_t)Value); Value = (Value - (wxDateTime::wxDateTime_t)Value) * 60.0;
219 m_pDateTime->SetMinute ((wxDateTime::wxDateTime_t)Value); Value = (Value - (wxDateTime::wxDateTime_t)Value) * 60.0;
220 m_pDateTime->SetSecond ((wxDateTime::wxDateTime_t)Value); Value = (Value - (wxDateTime::wxDateTime_t)Value) * 1000.0;
221 m_pDateTime->SetMillisecond((wxDateTime::wxDateTime_t)Value);
229 m_pDateTime->SetDay(Value);
237 m_pDateTime->SetMonth((wxDateTime::Month)Value);
245 m_pDateTime->SetYear(Value);
253 m_pDateTime->SetToYearDay(Value);
261 m_pDateTime->SetToCurrent();
269 m_pDateTime->ResetTime();
282 return(
CSG_DateTime(m_pDateTime->FromUTC(noDST).GetJDN()) );
290 return(
CSG_DateTime(m_pDateTime->ToUTC(noDST).GetJDN()) );
296 m_pDateTime->MakeUTC(noDST);
304 return( m_pDateTime->IsDST() != 0 );
315 return( m_pDateTime->GetValue().GetValue() );
328 return( dt.
Add(TimeSpan) );
333 m_pDateTime->Add(wxTimeSpan((wxLongLong)TimeSpan.m_span));
348 m_pDateTime->Subtract(wxTimeSpan((wxLongLong)TimeSpan.m_span));
356 CSG_TimeSpan Span((
sLong)m_pDateTime->Subtract(*DateTime.m_pDateTime).GetValue().GetValue());
369 return( m_pDateTime->IsValid() );
381 return( (
Month)m_pDateTime->GetMonth() );
386 return( m_pDateTime->GetYear() );
392 return( m_pDateTime->GetDayOfYear() );
397 return( (
WeekDay)m_pDateTime->GetWeekDay() );
413 return( m_pDateTime->GetJDN() );
418 return( m_pDateTime->GetMJD() );
452 wxString s(m_pDateTime->FormatDate());
CSG_String _s(&s);
return( _s );
457 wxString s(m_pDateTime->FormatTime());
CSG_String _s(&s);
return( _s );
462 wxString s(m_pDateTime->FormatISODate());
CSG_String _s(&s);
return( _s );
467 wxString s(m_pDateTime->FormatISOTime());
CSG_String _s(&s);
return( _s );
472 wxString s(m_pDateTime->FormatISOCombined(sep));
CSG_String _s(&s);
return( _s );
478 wxString::const_iterator end;
return( m_pDateTime->ParseDate(date.
c_str(), &end) );
483 wxString::const_iterator end;
return( m_pDateTime->ParseDateTime(datetime.
c_str(), &end) );
488 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), format.
c_str(), *dateDef.m_pDateTime, &end) );
493 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), format.
c_str(), &end) );
498 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), &end) );
504 return( m_pDateTime->ParseISOCombined(date.
c_str(), sep) );
509 return( m_pDateTime->ParseISODate(date.
c_str()) );
514 return( m_pDateTime->ParseISOTime(date.
c_str()) );
534 return( (
Month)wxDateTime::GetCurrentMonth() );
539 return( wxDateTime::GetCurrentYear() );
545 wxString s(wxDateTime::GetMonthName ((wxDateTime::Month)month , (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
550 wxString s(wxDateTime::GetEnglishMonthName ((wxDateTime::Month)month , (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
555 wxString s(wxDateTime::GetWeekDayName ((wxDateTime::WeekDay)weekday, (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
560 wxString s(wxDateTime::GetEnglishWeekDayName((wxDateTime::WeekDay)weekday, (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
566 return( (
TSG_DateTime)wxDateTime::GetNumberOfDays(year) );
571 return( (
TSG_DateTime)wxDateTime::GetNumberOfDays((wxDateTime::Month)month, year) );
577 return( wxDateTime::IsLeapYear(year) );
583 CSG_DateTime DateTime; *DateTime.m_pDateTime = wxDateTime::Now();
596 time_t tUnix = Seconds;
602 gmtime_s(&t, &tUnix);
616 h = 1721424.0 + (Hours - 12.0) / 24.0;
625 int day, mon, year, hour, min, sec;
629 h = 60.0 * (h - hour);
631 h = 60.0 * (h - min);
636 d = d - (146097 * n + 3) / 4;
637 year = 4000 * (d + 1) / 1461001;
638 d = d - 1461 * year / 4 + 31;
640 day = d - 2447 * mon / 80;
642 mon = mon + 2 - 12 * d;
643 year = 100 * (n - 49) + year + d;
660 Choices.
Printf(
"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
661 _TL(
"January"),
_TL(
"February"),
_TL(
"March" ),
_TL(
"April" ),
_TL(
"May" ),
_TL(
"June" ),
662 _TL(
"July" ),
_TL(
"August" ),
_TL(
"September"),
_TL(
"October"),
_TL(
"November"),
_TL(
"December")
680 double Z = floor(JDN + 0.5);
681 double F = JDN + 0.5 - Z;
682 double a = floor((Z - 1867216.25) / 36524.25);
683 double A = Z + 1 + a - floor(a / 4);
685 double C = floor((
B - 122.1) / 365.25);
686 double D = floor(365.25 *
C);
687 double E = floor((
B - D) / 30.6001);
689 d = int(
B - D - floor(30.6001 * E) + F);
693 m = E - 1; y =
C - 4716;
697 m = E - 13; y =
C - 4715;
714 Date.
Printf(
"%04d-%02d-%02d", y, m, d);
740 if( Month <= 2 ) { Year--; Month += 12; }
742 return( floor(365.25 * (Year + 4716)) + floor(30.6001 * (Month + 1)) + Day + 2. - floor(Year / 100) + floor(Year / 400) - 1524.5 );
756 bool BC = Date[0] ==
'-';
762 bool inv = ymd[2].Length() == 4;
764 int y = ymd[inv ? 2 : 0].asInt();
if( BC ) { y = -y; }
765 int m = ymd[ 1].asInt();
if( m < 1 ) { m = 1; }
else if( m > 12 ) { m = 12; }
766 int d = ymd[inv ? 0 : 2].asInt();
if( d < 1 ) { d = 1; }
else if( d > 31 ) { d = 31; }
788 static const int MidOfMonth[12] =
792 { 15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349 };
798 Month = (Month % 12) + 12;
799 Day = MidOfMonth[Month] - 365;
801 else if( Month >= 12 )
803 Month = (Month % 12);
804 Day = MidOfMonth[Month] + 365;
808 Day = MidOfMonth[Month];
811 if( bLeapYear && Month > 1 )
839 double T = (JDN - 2451545.) / 36525.;
841 double M = 357.52910 + 35999.05030 * T - 0.0001559 * T*T - 0.00000048 * T*T*T;
845 double L = (280.46645 + 36000.76983 * T + 0.0003032 * T*T)
846 + ((1.914600 - 0.004817 * T - 0.000014 * T*T) * sin(M)
847 + (0.019993 - 0.000101 * T) * sin(2. * M) + 0.000290 * sin(3. * M));
854 static const double Ecliptic_Obliquity =
M_DEG_TO_RAD * 23.43929111;
857 double Y = cos(Ecliptic_Obliquity) * sin(L);
858 double Z = sin(Ecliptic_Obliquity) * sin(L);
859 double R = sqrt(1. - Z*Z);
862 RA = 2. * atan2(Y, (X + R));
881 bool SG_Get_Sun_Position(
double JDN,
double Longitude,
double Latitude,
double &Height,
double &Azimuth,
bool bRefraction)
891 double T = (JDN - 2451545.) / 36525.;
893 double Theta = Longitude +
M_DEG_TO_RAD * (280.46061837 + 360.98564736629 * (JDN - 2451545.) + T*T * (0.000387933 - T / 38710000.));
895 double HA = Theta - RA;
900 Height = asin ( sin(Latitude) * sin(Dec) + cos(Latitude) * cos(Dec) * cos(HA));
901 Azimuth = atan2(-sin(HA) * cos(Dec), cos(Latitude) * sin(Dec) - sin(Latitude) * cos(Dec) * cos(HA));
908 if( Refraction >= 0. )
910 Height += Refraction;
914 return( Height > 0. );
957 z = 3.51823 * (0.1594 + z * (0.0196 + 0.00002 * z) ) / (1. + z * (0.505 + 0.0845 * z));
976 double JD = DayOfYear *
M_PI_360 / 365.;
978 double SunDec = 0.4093 * sin(JD - 1.405);
980 double d = -tanLat * tan(SunDec);
982 return( acos(d < -1 ? -1 : d < 1 ? d : 1) * 24. /
M_PI );