53#include <wx/datetime.h>
67 wxTimeSpan ts((wxLongLong(m_span)));
69 wxString s = !
Format.is_Empty() ? ts.Format(
Format.c_str()) : ts.Format(wxDefaultTimeSpanFormat);
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() );
423 return( m_pDateTime->GetTicks() );
451 wxString s(m_pDateTime->Format(
Format.c_str()));
CSG_String _s(&s);
return( _s );
456 wxString s(m_pDateTime->FormatDate());
CSG_String _s(&s);
return( _s );
461 wxString s(m_pDateTime->FormatTime());
CSG_String _s(&s);
return( _s );
466 wxString s(m_pDateTime->FormatISODate());
CSG_String _s(&s);
return( _s );
471 wxString s(m_pDateTime->FormatISOTime());
CSG_String _s(&s);
return( _s );
476 wxString s(m_pDateTime->FormatISOCombined(sep));
CSG_String _s(&s);
return( _s );
482 wxString::const_iterator end;
return( m_pDateTime->ParseDate(date.
c_str(), &end) );
487 wxString::const_iterator end;
return( m_pDateTime->ParseDateTime(datetime.
c_str(), &end) );
492 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), format.
c_str(), *dateDef.m_pDateTime, &end) );
497 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), format.
c_str(), &end) );
502 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), &end) );
508 return( m_pDateTime->ParseISOCombined(date.
c_str(), sep) );
513 return( m_pDateTime->ParseISODate(date.
c_str()) );
518 return( m_pDateTime->ParseISOTime(date.
c_str()) );
531 Now.Set_To_Current();
533 return(
Now.Get_Day() );
538 return( (
Month)wxDateTime::GetCurrentMonth() );
543 return( wxDateTime::GetCurrentYear() );
549 wxString s(wxDateTime::GetMonthName ((wxDateTime::Month)month , (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
554 wxString s(wxDateTime::GetEnglishMonthName ((wxDateTime::Month)month , (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
559 wxString s(wxDateTime::GetWeekDayName ((wxDateTime::WeekDay)weekday, (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
564 wxString s(wxDateTime::GetEnglishWeekDayName((wxDateTime::WeekDay)weekday, (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
570 return( (
TSG_DateTime)wxDateTime::GetNumberOfDays(year) );
575 return( (
TSG_DateTime)wxDateTime::GetNumberOfDays((wxDateTime::Month)month, year) );
581 return( wxDateTime::IsLeapYear(year) );
587 CSG_DateTime DateTime; *DateTime.m_pDateTime = wxDateTime::Now();
600 time_t tUnix = Seconds;
606 gmtime_s(&t, &tUnix);
620 h = 1721424.0 + (Hours - 12.0) / 24.0;
629 int day, mon, year, hour, min, sec;
633 h = 60.0 * (h - hour);
635 h = 60.0 * (h - min);
640 d = d - (146097 * n + 3) / 4;
641 year = 4000 * (d + 1) / 1461001;
642 d = d - 1461 * year / 4 + 31;
644 day = d - 2447 * mon / 80;
646 mon = mon + 2 - 12 * d;
647 year = 100 * (n - 49) + year + d;
664 Choices.
Printf(
"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
665 _TL(
"January"),
_TL(
"February"),
_TL(
"March" ),
_TL(
"April" ),
_TL(
"May" ),
_TL(
"June" ),
666 _TL(
"July" ),
_TL(
"August" ),
_TL(
"September"),
_TL(
"October"),
_TL(
"November"),
_TL(
"December")
684 double Z = floor(JDN + 0.5);
685 double F = JDN + 0.5 - Z;
686 double a = floor((Z - 1867216.25) / 36524.25);
687 double A = Z + 1 + a - floor(a / 4);
689 double C = floor((
B - 122.1) / 365.25);
690 double D = floor(365.25 *
C);
691 double E = floor((
B - D) / 30.6001);
693 d = int(
B - D - floor(30.6001 * E) + F);
697 m = E - 1; y =
C - 4716;
701 m = E - 13; y =
C - 4715;
718 Date.
Printf(
"%04d-%02d-%02d", y, m, d);
744 if( Month <= 2 ) { Year--; Month += 12; }
746 return( floor(365.25 * (Year + 4716)) + floor(30.6001 * (Month + 1)) + Day + 2. - floor(Year / 100) + floor(Year / 400) - 1524.5 );
760 bool BC = Date[0] ==
'-';
766 bool inv = ymd[2].Length() == 4;
768 int y = ymd[inv ? 2 : 0].asInt();
if( BC ) { y = -y; }
769 int m = ymd[ 1].asInt();
if( m < 1 ) { m = 1; }
else if( m > 12 ) { m = 12; }
770 int d = ymd[inv ? 0 : 2].asInt();
if( d < 1 ) { d = 1; }
else if( d > 31 ) { d = 31; }
792 static const int MidOfMonth[12] =
796 { 15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349 };
802 Month = (Month % 12) + 12;
803 Day = MidOfMonth[Month] - 365;
805 else if( Month >= 12 )
807 Month = (Month % 12);
808 Day = MidOfMonth[Month] + 365;
812 Day = MidOfMonth[Month];
815 if( bLeapYear && Month > 1 )
843 double T = (JDN - 2451545.) / 36525.;
845 double M = 357.52910 + 35999.05030 * T - 0.0001559 * T*T - 0.00000048 * T*T*T;
849 double L = (280.46645 + 36000.76983 * T + 0.0003032 * T*T)
850 + ((1.914600 - 0.004817 * T - 0.000014 * T*T) * sin(M)
851 + (0.019993 - 0.000101 * T) * sin(2. * M) + 0.000290 * sin(3. * M));
858 static const double Ecliptic_Obliquity =
M_DEG_TO_RAD * 23.43929111;
861 double Y = cos(Ecliptic_Obliquity) * sin(L);
862 double Z = sin(Ecliptic_Obliquity) * sin(L);
863 double R = sqrt(1. - Z*Z);
866 RA = 2. * atan2(Y, (X + R));
885bool SG_Get_Sun_Position(
double JDN,
double Longitude,
double Latitude,
double &Height,
double &Azimuth,
bool bRefraction)
895 double T = (JDN - 2451545.) / 36525.;
897 double Theta = Longitude +
M_DEG_TO_RAD * (280.46061837 + 360.98564736629 * (JDN - 2451545.) + T*T * (0.000387933 - T / 38710000.));
899 double HA = Theta - RA;
904 Height = asin ( sin(Latitude) * sin(Dec) + cos(Latitude) * cos(Dec) * cos(HA));
905 Azimuth = atan2(-sin(HA) * cos(Dec), cos(Latitude) * sin(Dec) - sin(Latitude) * cos(Dec) * cos(HA));
912 if( Refraction >= 0. )
914 Height += Refraction;
918 return( Height > 0. );
961 z = 3.51823 * (0.1594 + z * (0.0196 + 0.00002 * z) ) / (1. + z * (0.505 + 0.0845 * z));
980 double JD = DayOfYear *
M_PI_360 / 365.;
982 double SunDec = 0.4093 * sin(JD - 1.405);
984 double d = -tanLat * tan(SunDec);
986 return( acos(d < -1 ? -1 : d < 1 ? d : 1) * 24. /
M_PI );
SAGA_API_DLL_EXPORT CSG_Strings SG_String_Tokenize(const CSG_String &String, const CSG_String &Delimiters=SG_DEFAULT_DELIMITERS, TSG_String_Tokenizer_Mode Mode=SG_TOKEN_DEFAULT)
TSG_DateTime Get_WeekOfMonth(void) const
CSG_DateTime Add(const CSG_TimeSpan &TimeSpan) const
bool is_Between(const CSG_DateTime &t1, const CSG_DateTime &t2) const
unsigned short Get_Millisecond(void) const
sLong Get_Unix_Time(void) const
unsigned short Get_DayOfYear(void) const
unsigned short Get_Minute(void) const
static CSG_String Get_EnglishWeekDayName(WeekDay weekday, NameFlags flags=Name_Full)
CSG_DateTime & Reset_Time(void)
static TSG_DateTime Get_NumberOfDays(int year)
CSG_DateTime & Set_Year(int Value)
CSG_String Format_Time(void) const
CSG_String Format(const CSG_String &Format="") const
static CSG_String Get_Month_Choices(void)
CSG_DateTime & Set_Hours_AD(int Hours)
bool Parse_ISOTime(const CSG_String &date)
CSG_DateTime & Set_Day(unsigned short Value)
CSG_DateTime & Set_DayOfYear(unsigned short Value)
bool Parse_Date(const CSG_String &date)
sLong Get_Value(void) const
static CSG_String Get_MonthName(Month month, NameFlags flags=Name_Full)
static int Get_Current_Year(void)
Month Get_Month(void) const
double Get_MJD(void) const
static CSG_String Get_EnglishMonthName(Month month, NameFlags flags=Name_Full)
CSG_DateTime & Set_To_Current(void)
CSG_DateTime From_UTC(bool noDST=false) const
bool is_EarlierThan(const CSG_DateTime &DateTime) const
unsigned short Get_Second(void) const
bool is_SameDate(const CSG_DateTime &DateTime) const
static bool is_LeapYear(int year=Inv_Year)
CSG_String Format_ISOCombined(char sep='T') const
bool is_EqualTo(const CSG_DateTime &DateTime) const
CSG_String Format_ISOTime(void) const
CSG_DateTime & Make_UTC(bool noDST=false)
CSG_DateTime To_UTC(bool noDST=false) const
bool Parse_DateTime(const CSG_String &datetime)
CSG_DateTime & Set_Minute(unsigned short Value)
CSG_DateTime & Set_Millisecond(unsigned short Value)
static Month Get_Current_Month(void)
static TSG_DateTime Get_Current_Day(void)
unsigned short TSG_DateTime
WeekDay Get_WeekDay(void) const
CSG_DateTime & Set_Unix_Time(sLong Seconds)
CSG_String Format_ISODate(void) const
double Get_JDN(void) const
CSG_DateTime & Set_Month(unsigned short Value)
CSG_String Format_Date(void) const
unsigned short Get_Day(void) const
bool is_StrictlyBetween(const CSG_DateTime &t1, const CSG_DateTime &t2) const
bool is_Valid(void) const
bool is_SameTime(const CSG_DateTime &DateTime) const
static CSG_DateTime Now(void)
virtual ~CSG_DateTime(void)
unsigned short Get_Hour(void) const
bool Parse_ISODate(const CSG_String &date)
bool Parse_Format(const CSG_String &date, const CSG_String &format, const CSG_DateTime &dateDef)
bool Parse_ISOCombined(const CSG_String &date, char sep='T')
CSG_DateTime Subtract(const CSG_TimeSpan &TimeSpan) const
CSG_DateTime & Set(const CSG_DateTime &DateTime)
bool is_LaterThan(const CSG_DateTime &DateTime) const
static CSG_String Get_WeekDayName(WeekDay weekday, NameFlags flags=Name_Full)
CSG_DateTime & Set_Hour(unsigned short Value)
CSG_DateTime & Set_Second(unsigned short Value)
TSG_DateTime Get_WeekOfYear(void) const
size_t Length(void) const
CSG_String AfterFirst(char Character) const
CSG_String Right(size_t count) const
const SG_Char * c_str(void) const
int Printf(const char *Format,...)
CSG_String Mid(size_t first, size_t count=0) const
CSG_String Left(size_t count) const
int Get_Count(void) const
CSG_String Format(const CSG_String &format="") const
bool Create(const CSG_Vector &Vector)
double SG_Get_Sun_Refraction(double Height, bool bRadians)
bool SG_JulianDayNumber_To_Date(double JDN, int &y, int &m, int &d)
double SG_Get_Day_Length(int DayOfYear, double Latitude)
int SG_Get_Day_MidOfMonth(int Month, bool bLeapYear)
bool SG_Get_Sun_Position(double JDN, double &RA, double &Dec)
double SG_Date_To_JulianDayNumber(int Year, int Month, int Day)