|
@@ -86,12 +86,7 @@ struct intern_date
|
|
long mminutes;
|
|
long mminutes;
|
|
long mseconds;
|
|
long mseconds;
|
|
|
|
|
|
- enum STR_FORMAT
|
|
|
|
- {
|
|
|
|
- extended, //"%Y-%m-%d %H:%M:%S"
|
|
|
|
- ymd, //"%Y-%m-%d"
|
|
|
|
- hms //"%H:%M:%S"
|
|
|
|
- };
|
|
|
|
|
|
+
|
|
|
|
|
|
intern_date() noexcept
|
|
intern_date() noexcept
|
|
: myear(1400)
|
|
: myear(1400)
|
|
@@ -133,11 +128,11 @@ struct intern_date
|
|
mseconds = std::floor(f);
|
|
mseconds = std::floor(f);
|
|
}
|
|
}
|
|
|
|
|
|
- std::string toString(STR_FORMAT fmt) noexcept
|
|
|
|
|
|
+ std::string toString(DateFormat fmt) noexcept
|
|
{
|
|
{
|
|
std::stringstream ss;
|
|
std::stringstream ss;
|
|
|
|
|
|
- if (fmt != hms) {
|
|
|
|
|
|
+ if (fmt != DATE_FORMAT_HMS) {
|
|
ss << myear << "-";
|
|
ss << myear << "-";
|
|
if (mmonth < 10) {
|
|
if (mmonth < 10) {
|
|
ss << "0";
|
|
ss << "0";
|
|
@@ -148,10 +143,10 @@ struct intern_date
|
|
}
|
|
}
|
|
ss << mday ;
|
|
ss << mday ;
|
|
}
|
|
}
|
|
- if (fmt == extended) {
|
|
|
|
|
|
+ if (fmt == DATE_FORMAT_EXTENDED) {
|
|
ss << " ";
|
|
ss << " ";
|
|
}
|
|
}
|
|
- if (fmt != ymd) {
|
|
|
|
|
|
+ if (fmt != DATE_FORMAT_YMD) {
|
|
if (mhours < 10) {
|
|
if (mhours < 10) {
|
|
ss << "0";
|
|
ss << "0";
|
|
}
|
|
}
|
|
@@ -173,11 +168,11 @@ struct intern_date
|
|
//format : not extended = "%Y-%m-%d"
|
|
//format : not extended = "%Y-%m-%d"
|
|
// extended = "%Y-%m-%d %H:%M:%S"
|
|
// extended = "%Y-%m-%d %H:%M:%S"
|
|
//return true if no error
|
|
//return true if no error
|
|
- bool fromString(const std::string& date, STR_FORMAT toparse) noexcept
|
|
|
|
|
|
+ bool fromString(const std::string& date, DateFormat toparse) noexcept
|
|
{
|
|
{
|
|
bool error = false;
|
|
bool error = false;
|
|
|
|
|
|
- if (toparse == extended) {
|
|
|
|
|
|
+ if (toparse == DATE_FORMAT_EXTENDED) {
|
|
//parse "%Y-%m-%d %H:%M:%S"
|
|
//parse "%Y-%m-%d %H:%M:%S"
|
|
try {
|
|
try {
|
|
std::regex regex("([^\\s]+)\\s([^\\s]+)");
|
|
std::regex regex("([^\\s]+)\\s([^\\s]+)");
|
|
@@ -189,8 +184,8 @@ struct intern_date
|
|
std::smatch match = *next;
|
|
std::smatch match = *next;
|
|
|
|
|
|
if (match.size() == 3) {
|
|
if (match.size() == 3) {
|
|
- fromString(match[1].str(), ymd);
|
|
|
|
- fromString(match[2].str(), hms);
|
|
|
|
|
|
+ fromString(match[1].str(), DATE_FORMAT_YMD);
|
|
|
|
+ fromString(match[2].str(), DATE_FORMAT_HMS);
|
|
} else {
|
|
} else {
|
|
error = true;
|
|
error = true;
|
|
}
|
|
}
|
|
@@ -212,19 +207,19 @@ struct intern_date
|
|
std::smatch match = *next;
|
|
std::smatch match = *next;
|
|
nbmatches++;
|
|
nbmatches++;
|
|
if (nbmatches == 1) {
|
|
if (nbmatches == 1) {
|
|
- if (toparse == ymd) {
|
|
|
|
|
|
+ if (toparse == DATE_FORMAT_YMD) {
|
|
myear = std::stol(match.str());
|
|
myear = std::stol(match.str());
|
|
} else {
|
|
} else {
|
|
mhours = std::stol(match.str());
|
|
mhours = std::stol(match.str());
|
|
}
|
|
}
|
|
} else if (nbmatches == 3) {
|
|
} else if (nbmatches == 3) {
|
|
- if (toparse == ymd) {
|
|
|
|
|
|
+ if (toparse == DATE_FORMAT_YMD) {
|
|
mmonth = std::stol(match.str());
|
|
mmonth = std::stol(match.str());
|
|
} else {
|
|
} else {
|
|
mminutes = std::stol(match.str());
|
|
mminutes = std::stol(match.str());
|
|
}
|
|
}
|
|
} else if (nbmatches == 5) {
|
|
} else if (nbmatches == 5) {
|
|
- if (toparse == ymd) {
|
|
|
|
|
|
+ if (toparse == DATE_FORMAT_YMD) {
|
|
mday = std::stol(match.str());
|
|
mday = std::stol(match.str());
|
|
} else {
|
|
} else {
|
|
mseconds = std::stol(match.str());
|
|
mseconds = std::stol(match.str());
|
|
@@ -596,7 +591,7 @@ std::string DateTime::toJulianDayNumber(unsigned long date)
|
|
{
|
|
{
|
|
intern_date d;
|
|
intern_date d;
|
|
d.fromJulianDay(static_cast<double>(date));
|
|
d.fromJulianDay(static_cast<double>(date));
|
|
- return d.toString(intern_date::ymd);
|
|
|
|
|
|
+ return d.toString(DATE_FORMAT_YMD);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -604,7 +599,7 @@ std::string DateTime::toJulianDayNumber(unsigned long date)
|
|
long DateTime::toJulianDayNumber(const std::string& date)
|
|
long DateTime::toJulianDayNumber(const std::string& date)
|
|
{
|
|
{
|
|
intern_date d;
|
|
intern_date d;
|
|
- d.fromString(date, intern_date::ymd);
|
|
|
|
|
|
+ d.fromString(date, DATE_FORMAT_YMD);
|
|
return d.julianDayNumber();
|
|
return d.julianDayNumber();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -613,7 +608,13 @@ std::string DateTime::toJulianDay(double date)
|
|
{
|
|
{
|
|
intern_date d;
|
|
intern_date d;
|
|
d.fromJulianDay(date);
|
|
d.fromJulianDay(date);
|
|
- return d.toString(intern_date::extended);
|
|
|
|
|
|
+ return d.toString(DATE_FORMAT_EXTENDED);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+std::string DateTime::toJulianDayFmt(double date, DateFormat format){
|
|
|
|
+ intern_date d;
|
|
|
|
+ d.fromJulianDay(date);
|
|
|
|
+ return d.toString(format);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -622,7 +623,7 @@ double DateTime::toJulianDay(const std::string& date)
|
|
{
|
|
{
|
|
|
|
|
|
intern_date d;
|
|
intern_date d;
|
|
- d.fromString(date, intern_date::extended);
|
|
|
|
|
|
+ d.fromString(date, DATE_FORMAT_EXTENDED);
|
|
return d.julianDay();
|
|
return d.julianDay();
|
|
}
|
|
}
|
|
|
|
|