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() );
386 return( (
Month)m_pDateTime->GetMonth() );
396 return( bZeroBased ? (
int)m_pDateTime->GetMonth() : 1 + (
int)m_pDateTime->GetMonth() );
401 return( m_pDateTime->GetYear() );
407 return( m_pDateTime->GetDayOfYear() );
412 return( (
WeekDay)m_pDateTime->GetWeekDay() );
428 return( m_pDateTime->GetJDN() );
433 return( m_pDateTime->GetMJD() );
438 return( m_pDateTime->GetTicks() );
466 wxString s(m_pDateTime->Format(
Format.c_str()));
CSG_String _s(&s);
return( _s );
471 wxString s(m_pDateTime->FormatDate());
CSG_String _s(&s);
return( _s );
476 wxString s(m_pDateTime->FormatTime());
CSG_String _s(&s);
return( _s );
481 wxString s(m_pDateTime->FormatISODate());
CSG_String _s(&s);
return( _s );
486 wxString s(m_pDateTime->FormatISOTime());
CSG_String _s(&s);
return( _s );
491 wxString s(m_pDateTime->FormatISOCombined(sep));
CSG_String _s(&s);
return( _s );
497 wxString::const_iterator end;
return( m_pDateTime->ParseDate(date.
c_str(), &end) );
502 wxString::const_iterator end;
return( m_pDateTime->ParseDateTime(datetime.
c_str(), &end) );
507 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), format.
c_str(), *dateDef.m_pDateTime, &end) );
512 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), format.
c_str(), &end) );
517 wxString::const_iterator end;
return( m_pDateTime->ParseFormat(date.
c_str(), &end) );
523 return( m_pDateTime->ParseISOCombined(date.
c_str(), sep) );
528 return( m_pDateTime->ParseISODate(date.
c_str()) );
533 return( m_pDateTime->ParseISOTime(date.
c_str()) );
546 Now.Set_To_Current();
548 return(
Now.Get_Day() );
553 return( (
Month)wxDateTime::GetCurrentMonth() );
558 return( wxDateTime::GetCurrentYear() );
564 wxString s(wxDateTime::GetMonthName ((wxDateTime::Month)month , (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
569 wxString s(wxDateTime::GetEnglishMonthName ((wxDateTime::Month)month , (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
574 wxString s(wxDateTime::GetWeekDayName ((wxDateTime::WeekDay)weekday, (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
579 wxString s(wxDateTime::GetEnglishWeekDayName((wxDateTime::WeekDay)weekday, (wxDateTime::NameFlags)flags));
CSG_String _s(&s);
return( _s );
585 return( (
TSG_DateTime)wxDateTime::GetNumberOfDays(year) );
590 return( (
TSG_DateTime)wxDateTime::GetNumberOfDays((wxDateTime::Month)month, year) );
596 return( wxDateTime::IsLeapYear(year) );
602 CSG_DateTime DateTime; *DateTime.m_pDateTime = wxDateTime::Now();
615 time_t tUnix = Seconds;
621 gmtime_s(&t, &tUnix);
635 h = 1721424.0 + (Hours - 12.0) / 24.0;
644 int day, mon, year, hour, min, sec;
648 h = 60.0 * (h - hour);
650 h = 60.0 * (h - min);
655 d = d - (146097 * n + 3) / 4;
656 year = 4000 * (d + 1) / 1461001;
657 d = d - 1461 * year / 4 + 31;
659 day = d - 2447 * mon / 80;
661 mon = mon + 2 - 12 * d;
662 year = 100 * (n - 49) + year + d;
679 Choices.
Printf(
"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
680 _TL(
"January"),
_TL(
"February"),
_TL(
"March" ),
_TL(
"April" ),
_TL(
"May" ),
_TL(
"June" ),
681 _TL(
"July" ),
_TL(
"August" ),
_TL(
"September"),
_TL(
"October"),
_TL(
"November"),
_TL(
"December")
699 double Z = floor(JDN + 0.5);
700 double F = JDN + 0.5 - Z;
701 double a = floor((Z - 1867216.25) / 36524.25);
702 double A = Z + 1 + a - floor(a / 4);
704 double C = floor((
B - 122.1) / 365.25);
705 double D = floor(365.25 *
C);
706 double E = floor((
B - D) / 30.6001);
708 d = int(
B - D - floor(30.6001 * E) + F);
712 m = E - 1; y =
C - 4716;
716 m = E - 13; y =
C - 4715;
733 Date.
Printf(
"%04d-%02d-%02d", y, m, d);
759 if( Month <= 2 ) { Year--; Month += 12; }
761 return( floor(365.25 * (Year + 4716)) + floor(30.6001 * (Month + 1)) + Day + 2. - floor(Year / 100) + floor(Year / 400) - 1524.5 );
775 bool BC = Date[0] ==
'-';
781 bool inv = ymd[2].Length() == 4;
783 int y = ymd[inv ? 2 : 0].asInt();
if( BC ) { y = -y; }
784 int m = ymd[ 1].asInt();
if( m < 1 ) { m = 1; }
else if( m > 12 ) { m = 12; }
785 int d = ymd[inv ? 0 : 2].asInt();
if( d < 1 ) { d = 1; }
else if( d > 31 ) { d = 31; }
807 static const int MidOfMonth[12] =
811 { 15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349 };
817 Month = (Month % 12) + 12;
818 Day = MidOfMonth[Month] - 365;
820 else if( Month >= 12 )
822 Month = (Month % 12);
823 Day = MidOfMonth[Month] + 365;
827 Day = MidOfMonth[Month];
830 if( bLeapYear && Month > 1 )
858 double T = (JDN - 2451545.) / 36525.;
860 double M = 357.52910 + 35999.05030 * T - 0.0001559 * T*T - 0.00000048 * T*T*T;
864 double L = (280.46645 + 36000.76983 * T + 0.0003032 * T*T)
865 + ((1.914600 - 0.004817 * T - 0.000014 * T*T) * sin(M)
866 + (0.019993 - 0.000101 * T) * sin(2. * M) + 0.000290 * sin(3. * M));
873 static const double Ecliptic_Obliquity =
M_DEG_TO_RAD * 23.43929111;
876 double Y = cos(Ecliptic_Obliquity) * sin(L);
877 double Z = sin(Ecliptic_Obliquity) * sin(L);
878 double R = sqrt(1. - Z*Z);
881 RA = 2. * atan2(Y, (X + R));
900bool SG_Get_Sun_Position(
double JDN,
double Longitude,
double Latitude,
double &Height,
double &Azimuth,
bool bRefraction)
910 double T = (JDN - 2451545.) / 36525.;
912 double Theta = Longitude +
M_DEG_TO_RAD * (280.46061837 + 360.98564736629 * (JDN - 2451545.) + T*T * (0.000387933 - T / 38710000.));
914 double HA = Theta - RA;
919 Height = asin ( sin(Latitude) * sin(Dec) + cos(Latitude) * cos(Dec) * cos(HA));
920 Azimuth = atan2(-sin(HA) * cos(Dec), cos(Latitude) * sin(Dec) - sin(Latitude) * cos(Dec) * cos(HA));
927 if( Refraction >= 0. )
929 Height += Refraction;
933 return( Height > 0. );
976 z = 3.51823 * (0.1594 + z * (0.0196 + 0.00002 * z) ) / (1. + z * (0.505 + 0.0845 * z));
995 double JD = DayOfYear *
M_PI_360 / 365.;
997 double SunDec = 0.4093 * sin(JD - 1.405);
999 double d = -tanLat * tan(SunDec);
1001 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
Returns the month as enum CSG_DateTime::Month (zero based, Jan = 0, Feb = 1, ...),...
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
bool asInt(int &Value) 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)