diff --git a/main.cpp b/main.cpp index 3a4a2af5..5bf1c94e 100644 --- a/main.cpp +++ b/main.cpp @@ -63,13 +63,9 @@ int main(int argc, char *argv[]) { c.start(); piMSleep(3000);*/ - PIStringList sl; - sl << "one" << "two" << "three"; - PIVariantTypes::Enum e; - e << sl; - e.selectValue(1); - PIVariant v = e; - piCout << v.value(); + PISystemTime st = PISystemTime::current(); + piCout << PIDateTime::current(); + piCout << PIDateTime::fromSystemTime(st); return 0; } diff --git a/src/core/piinit.cpp b/src/core/piinit.cpp index 2e94649d..fc980855 100644 --- a/src/core/piinit.cpp +++ b/src/core/piinit.cpp @@ -118,7 +118,7 @@ PIInit::PIInit() { WSAStartup(MAKEWORD(2, 2), &wsaData); // Timers init - SYSTEMTIME jan1970 = {1970, 1, 4, 1, 0, 14, 15, 0}; + SYSTEMTIME jan1970 = {1970, 1, 4, 1, 0, 0, 0, 0}; SystemTimeToFileTime(&jan1970, &__pi_ftjan1970); LARGE_INTEGER pf; pf.QuadPart = -1; diff --git a/src/core/pitime.cpp b/src/core/pitime.cpp index b40d5dde..8088ed22 100755 --- a/src/core/pitime.cpp +++ b/src/core/pitime.cpp @@ -463,3 +463,42 @@ double PITimeMeasurer::elapsed_s() const { PISystemTime PITimeMeasurer::elapsed() const { return (PISystemTime::current(true) - t_st); } + + +PICout operator <<(PICout s, const PITime & v) { + s.space(); + s.setControl(0, true); + s << "PITime(" << v.hours << ":"; + s << PIString::fromNumber(v.minutes).expandLeftTo(2, '0') << ":"; + s << PIString::fromNumber(v.seconds).expandLeftTo(2, '0') << ":"; + s << PIString::fromNumber(v.milliseconds).expandLeftTo(3, '0') << ")"; + s.restoreControl(); + return s; +} + + +PICout operator <<(PICout s, const PIDate & v) { + s.space(); + s.setControl(0, true); + s << "PIDate(" << v.day << "-"; + s << PIString::fromNumber(v.month).expandLeftTo(2, '0') << "-"; + s << v.year << ")"; + s.restoreControl(); + return s; +} + + +PICout operator <<(PICout s, const PIDateTime & v) { + s.space(); + s.setControl(0, true); + s << "PIDateTime("; + s << v.day << "-"; + s << PIString::fromNumber(v.month).expandLeftTo(2, '0') << "-"; + s << v.year << " "; + s << v.hours << ":"; + s << PIString::fromNumber(v.minutes).expandLeftTo(2, '0') << ":"; + s << PIString::fromNumber(v.seconds).expandLeftTo(2, '0') << ":"; + s << PIString::fromNumber(v.milliseconds).expandLeftTo(3, '0') << ")"; + s.restoreControl(); + return s; +} diff --git a/src/core/pitime.h b/src/core/pitime.h index 95a8449b..e4023d9b 100755 --- a/src/core/pitime.h +++ b/src/core/pitime.h @@ -29,6 +29,7 @@ # include #endif + #ifdef DOXYGEN //! \brief Sleep for "msecs" milliseconds void msleep(int msecs); @@ -56,6 +57,9 @@ inline void piMSleep(double msecs) {piUSleep(int(msecs * 1000.));} // on !Window * \details This function exec \a piUSleep (msecs * 1000000). */ inline void piSleep(double secs) {piUSleep(int(secs * 1000000.));} // on !Windows consider constant "usleep" offset + + + class PIP_EXPORT PISystemTime { public: @@ -176,7 +180,7 @@ private: }; -//! \relatesalso PICout \relatesalso PIByteArray \brief Output operator to PICout +//! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout inline PICout operator <<(PICout s, const PISystemTime & v) {s.space(); s.setControl(0, true); s << "(" << v.seconds << " s, " << v.nanoseconds << " ns)"; s.restoreControl(); return s;} //! \relatesalso PISystemTime \relatesalso PIByteArray \brief Output operator to PIByteArray @@ -185,6 +189,9 @@ inline PIByteArray & operator <<(PIByteArray & s, const PISystemTime & v) {s << //! \relatesalso PISystemTime \relatesalso PIByteArray \brief Input operator from PIByteArray inline PIByteArray & operator >>(PIByteArray & s, PISystemTime & v) {s >> v.seconds >> v.nanoseconds; return s;} + + + struct PIP_EXPORT PITime { PITime(int hours_ = 0, int minutes_ = 0, int seconds_ = 0, int milliseconds_ = 0): hours(hours_), minutes(minutes_), seconds(seconds_), milliseconds(milliseconds_) {;} int hours; @@ -196,6 +203,7 @@ struct PIP_EXPORT PITime { static PITime current(); static PITime fromSystemTime(const PISystemTime & st); }; + PIP_EXPORT bool operator ==(const PITime & t0, const PITime & t1); PIP_EXPORT bool operator <(const PITime & t0, const PITime & t1); PIP_EXPORT bool operator >(const PITime & t0, const PITime & t1); @@ -205,6 +213,12 @@ inline bool operator >=(const PITime & t0, const PITime & t1) {return !(t0 < t1) inline PIByteArray & operator <<(PIByteArray & s, const PITime & v) {s << v.hours << v.minutes << v.seconds << v.milliseconds; return s;} inline PIByteArray & operator >>(PIByteArray & s, PITime & v) {s >> v.hours >> v.minutes >> v.seconds >> v.milliseconds; return s;} +//! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout +PICout operator <<(PICout s, const PITime & v); + + + + struct PIP_EXPORT PIDate { PIDate(int year_ = 0, int month_ = 0, int day_ = 0): year(year_), month(month_), day(day_) {;} int year; @@ -213,6 +227,7 @@ struct PIP_EXPORT PIDate { PIString toString(const PIString & format = "d.MM.yyyy") const; static PIDate current(); }; + PIP_EXPORT bool operator ==(const PIDate & t0, const PIDate & t1); PIP_EXPORT bool operator <(const PIDate & t0, const PIDate & t1); PIP_EXPORT bool operator >(const PIDate & t0, const PIDate & t1); @@ -222,6 +237,12 @@ inline bool operator >=(const PIDate & t0, const PIDate & t1) {return !(t0 < t1) inline PIByteArray & operator <<(PIByteArray & s, const PIDate & v) {s << v.year << v.month << v.day; return s;} inline PIByteArray & operator >>(PIByteArray & s, PIDate & v) {s >> v.year >> v.month >> v.day; return s;} +//! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout +PICout operator <<(PICout s, const PIDate & v); + + + + struct PIP_EXPORT PIDateTime { PIDateTime() {year = month = day = hours = minutes = seconds = milliseconds = 0;} PIDateTime(const PITime & time) {year = month = day = 0; hours = time.hours; minutes = time.minutes; seconds = time.seconds; milliseconds = time.milliseconds;} @@ -255,6 +276,7 @@ struct PIP_EXPORT PIDateTime { static PIDateTime fromSystemTime(const PISystemTime & st) {PIDateTime dt = fromSecondSinceEpoch(st.seconds); dt.milliseconds = piClampi(st.nanoseconds / 1000000, 0, 999); return dt;} static PIDateTime current(); }; + inline PIDateTime operator +(const PIDateTime & d0, const PIDateTime & d1) {PIDateTime td = d0; td += d1; return td.normalized();} inline PIDateTime operator -(const PIDateTime & d0, const PIDateTime & d1) {PIDateTime td = d0; td -= d1; return td.normalized();} PIP_EXPORT bool operator ==(const PIDateTime & t0, const PIDateTime & t1); @@ -266,6 +288,12 @@ inline bool operator >=(const PIDateTime & t0, const PIDateTime & t1) {return !( inline PIByteArray & operator <<(PIByteArray & s, const PIDateTime & v) {s << v.year << v.month << v.day << v.hours << v.minutes << v.seconds << v.milliseconds; return s;} inline PIByteArray & operator >>(PIByteArray & s, PIDateTime & v) {s >> v.year >> v.month >> v.day >> v.hours >> v.minutes >> v.seconds >> v.milliseconds; return s;} +//! \relatesalso PICout \relatesalso PICout \brief Output operator to PICout +PICout operator <<(PICout s, const PIDateTime & v); + + + + DEPRECATED inline PITime currentTime() {return PITime::current();} // obsolete, use PITime::current() instead DEPRECATED inline PIDate currentDate() {return PIDate::current();} // obsolete, use PIDate::current() instead DEPRECATED inline PIDateTime currentDateTime() {return PIDateTime::current();} // obsolete, use PIDateTime::current() instead diff --git a/src/core/pivariant.cpp b/src/core/pivariant.cpp index 0f3871b7..72279f37 100755 --- a/src/core/pivariant.cpp +++ b/src/core/pivariant.cpp @@ -503,6 +503,9 @@ PIString PIVariant::toString() const { case PIVariant::pivLDouble: {ldouble r; ba >> r; return PIString::fromNumber(r);} case PIVariant::pivComplexd: {complexd r; ba >> r; return PIString::fromNumber(r.real());} case PIVariant::pivComplexld: {complexld r; ba >> r; return PIString::fromNumber(r.real());} + case PIVariant::pivTime: {PITime r; ba >> r; return r.toString();} + case PIVariant::pivDate: {PIDate r; ba >> r; return r.toString();} + case PIVariant::pivDateTime: {PIDateTime r; ba >> r; return r.toString();} case PIVariant::pivString: {PIString r; ba >> r; return r;} case PIVariant::pivStringList: {PIStringList r; ba >> r; if (r.isEmpty()) return PIString(); return r.front();} case PIVariant::pivEnum: {PIVariantTypes::Enum r; ba >> r; return r.selectedName();}