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 int J = (int)floor(JDN);
681 int f = J + 1401 + (((4 * J + 274277) / 146097) * 3) / 4 - 38;
683 int g = (e % 1461) / 4;
686 d = (h % 153) / 5 + 1;
687 m = (h / 153 + 2) % 12 + 1;
688 y = (e / 1461) - 4716 + (12 + 2 - m) / 12;
700 JDN = 0.5 + floor(JDN);
708 Date.
Printf(
"%04d-%02d-%02d", y, m, d);
731 int a = m <= 2 ? 1 : 0;
736 double JDN = d + floor((153. * m + 2.) / 5.) + 365. * y + floor(y / 4.) - floor(y / 100.) + floor(y / 400.) - 32045.;
753 int bBC = Date[0] ==
'-' ? -1 : 1;
764 bool bISO = s[0].Length() == 4;
766 int y = s[bISO ? 0 : 2].asInt() * bBC;
767 int m = s[ 1 ].asInt();
if( m < 1 ) m = 1;
else if( m > 12 ) m = 12;
768 int d = s[bISO ? 2 : 0].asInt();
if( d < 1 ) d = 1;
else if( d > 31 ) d = 31;
786 static const int MidOfMonth[12] =
790 { 15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349 };
796 Month = (Month % 12) + 12;
797 Day = MidOfMonth[Month] - 365;
799 else if( Month >= 12 )
801 Month = (Month % 12);
802 Day = MidOfMonth[Month] + 365;
806 Day = MidOfMonth[Month];
809 if( bLeapYear && Month > 1 )
838 double T = (JulianDayNumber - 2451545.0 ) / 36525.0;
840 double M =
M_DEG_TO_RAD * (357.52910 + 35999.05030 * T - 0.0001559 * T*T - 0.00000048 * T*T*T);
841 double L =
M_DEG_TO_RAD * ((280.46645 + 36000.76983 * T + 0.0003032 * T*T)
842 + ((1.914600 - 0.004817 * T - 0.000014 * T*T) * sin(M)
843 + (0.019993 - 0.000101 * T) * sin(2.0 * M) + 0.000290 * sin(3.0 * M)));
848 static const double Ecliptic_Obliquity =
M_DEG_TO_RAD * 23.43929111;
851 double Y = cos(Ecliptic_Obliquity) * sin(L);
852 double Z = sin(Ecliptic_Obliquity) * sin(L);
853 double R = sqrt(1.0 - Z*Z);
856 RA = 2.0 * atan2(Y, (X + R));
875 bool SG_Get_Sun_Position(
double JulianDayNumber,
double Longitude,
double Latitude,
double &Height,
double &Azimuth)
885 double T = (JulianDayNumber - 2451545.0 ) / 36525.0;
887 double Theta = Longitude +
M_DEG_TO_RAD * (280.46061837 + 360.98564736629 * (JulianDayNumber - 2451545.0) + T*T * (0.000387933 - T / 38710000.0));
889 double Tau = Theta - RA;
894 Height = asin ( sin(Latitude) * sin(Delta) + cos(Latitude) * cos(Delta) * cos(Tau));
895 Azimuth = atan2(-sin(Tau) * cos(Delta), cos(Latitude) * sin(Delta) - sin(Latitude) * cos(Delta) * cos(Tau));
898 return( Height > 0.0 );
917 double JD = DayOfYear *
M_PI * 2. / 365.;
919 double SunDec = 0.4093 * sin(JD - 1.405);
921 double d = -tanLat * tan(SunDec);
923 return( acos(d < -1 ? -1 : d < 1 ? d : 1) * 24. /
M_PI );