This commit is contained in:
2022-03-26 21:47:57 +03:00
parent 5d98a7dd3a
commit 35d340aaab
3 changed files with 249 additions and 60 deletions

View File

@@ -35,20 +35,20 @@
//! \addtogroup Core
//! \{
//! \class PISystemTime pitime.h
//! \~\class PITime pidatetime.h
//! \brief
//! \~english System time with nanosecond precision
//! \~russian Системное время с точностью до наносекунд
//! \~english Calendar time
//! \~russian Календарное время
//!
//! \~english \section PISystemTime_sec0 Synopsis
//! \~russian \section PISystemTime_sec0 Краткий обзор
//! \~english
//! \~\class PIDate pidatetime.h
//! \brief
//! \~english Calendar date
//! \~russian Календарная дата
//!
//! \~russian
//!
//! \~english \section PISystemTime_sec1 Example
//! \~russian \section PISystemTime_sec1 Пример
//! \~\snippet pitimer.cpp system_time
//! \~\class PIDateTime pidatetime.h
//! \brief
//! \~english Calendar date and time
//! \~russian Календарное дата и время
//!
//! \}

View File

@@ -30,23 +30,68 @@
#include "pisystemtime.h"
struct PIP_EXPORT PITime {
class PIP_EXPORT PITime {
public:
//! \~english Construct %PITime from hours, minutes, seconds and milliseconds
//! \~russian Создает %PITime из часов, минут, секунд и миллисекунд
PITime(int hours_ = 0, int minutes_ = 0, int seconds_ = 0, int milliseconds_ = 0): hours(hours_), minutes(minutes_), seconds(seconds_), milliseconds(milliseconds_) {;}
int hours;
int minutes;
int seconds;
int milliseconds;
//! \~english Returns string representation
//! \~russian Возвращает строковое представление
PIString toString(const PIString & format = "h:mm:ss") const;
//! \~english Returns time as %PISystemTime
//! \~russian Возвращает время как %PISystemTime
PISystemTime toSystemTime() const;
//! \~english Returns current time
//! \~russian Возвращает текущее время
static PITime current();
//! \~english Construct %PITime from %PISystemTime
//! \~russian Создает %PITime из %PISystemTime
static PITime fromSystemTime(const PISystemTime & st);
//! \~english Hour, 0-23
//! \~russian Час, 0-23
int hours;
//! \~english Minutes, 0-59
//! \~russian Минуты, 0-59
int minutes;
//! \~english Seconds, 0-59
//! \~russian Секунды, 0-59
int seconds;
//! \~english Milliseconds, 0-999
//! \~russian Миллисекунды, 0-999
int milliseconds;
};
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator ==(const PITime & t0, const PITime & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator <(const PITime & t0, const PITime & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator >(const PITime & t0, const PITime & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator !=(const PITime & t0, const PITime & t1) {return !(t0 == t1);}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator <=(const PITime & t0, const PITime & t1) {return !(t0 > t1);}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator >=(const PITime & t0, const PITime & t1) {return !(t0 < t1);}
//! \relatesalso PICout
@@ -57,20 +102,56 @@ PIP_EXPORT PICout operator <<(PICout s, const PITime & v);
struct PIP_EXPORT PIDate {
class PIP_EXPORT PIDate {
public:
//! \~english Construct %PIDate from year, month and day
//! \~russian Создает %PIDate из года, месяца и дня
PIDate(int year_ = 0, int month_ = 0, int day_ = 0): year(year_), month(month_), day(day_) {;}
int year;
int month;
int day;
//! \~english Returns string representation
//! \~russian Возвращает строковое представление
PIString toString(const PIString & format = "d.MM.yyyy") const;
//! \~english Returns current date
//! \~russian Возвращает текущую дату
static PIDate current();
//! \~english Year
//! \~russian Год
int year;
//! \~english Month, 1-12
//! \~russian Месяц, 1-12
int month;
//! \~english Day, 1-31
//! \~russian День, 1-31
int day;
};
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator ==(const PIDate & t0, const PIDate & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator <(const PIDate & t0, const PIDate & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator >(const PIDate & t0, const PIDate & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator !=(const PIDate & t0, const PIDate & t1) {return !(t0 == t1);}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator <=(const PIDate & t0, const PIDate & t1) {return !(t0 > t1);}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator >=(const PIDate & t0, const PIDate & t1) {return !(t0 < t1);}
//! \relatesalso PICout
@@ -81,43 +162,151 @@ PIP_EXPORT PICout operator <<(PICout s, const PIDate & v);
struct PIP_EXPORT PIDateTime {
class PIP_EXPORT PIDateTime {
public:
//! \~english Construct null %PIDateTime
//! \~russian Создает нулевой %PIDateTime
PIDateTime() {year = month = day = hours = minutes = seconds = milliseconds = 0;}
//! \~english Construct %PIDateTime from %PITime and null %PIDate
//! \~russian Создает %PIDateTime из %PITime и нулевого %PIDate
PIDateTime(const PITime & time) {year = month = day = 0; hours = time.hours; minutes = time.minutes; seconds = time.seconds; milliseconds = time.milliseconds;}
//! \~english Construct %PIDateTime from %PIDate and null %PITime
//! \~russian Создает %PIDateTime из %PIDate и нулевого %PITime
PIDateTime(const PIDate & date) {year = date.year; month = date.month; day = date.day; hours = minutes = seconds = milliseconds = 0;}
//! \~english Construct %PIDateTime from %PIDate and %PITime
//! \~russian Создает %PIDateTime из %PIDate и %PITime
PIDateTime(const PIDate & date, const PITime & time) {year = date.year; month = date.month; day = date.day; hours = time.hours; minutes = time.minutes; seconds = time.seconds; milliseconds = time.milliseconds;}
int year;
int month;
int day;
int hours;
int minutes;
int seconds;
int milliseconds;
//! \~english Returns normalized %PIDateTime
//! \~russian Возвращает нормализованный %PIDateTime
PIDateTime normalized() const {return PIDateTime::fromSecondSinceEpoch(toSecondSinceEpoch());}
//! \~english Normalize all fields
//! \~russian Нормализует все поля
void normalize() {*this = normalized();}
//! \~english Returns string representation
//! \~russian Возвращает строковое представление
PIString toString(const PIString & format = "h:mm:ss d.MM.yyyy") const;
//! \~english Returns seconds since 1 Jan 1970
//! \~russian Возвращает секунды от 1 Янв 1970
time_t toSecondSinceEpoch() const;
//! \~english Returns time as %PISystemTime
//! \~russian Возвращает время как %PISystemTime
PISystemTime toSystemTime() const {return PISystemTime(int(toSecondSinceEpoch()), milliseconds * 1000000);}
//! \~english Returns date part
//! \~russian Возвращает дату
PIDate date() const {return PIDate(year, month, day);}
//! \~english Returns time part
//! \~russian Возвращает время
PITime time() const {return PITime(hours, minutes, seconds, milliseconds);}
//! \~english Set date part
//! \~russian Устанавливает дату
void setDate(const PIDate & d) {year = d.year; month = d.month; day = d.day;}
//! \~english Set time part
//! \~russian Устанавливает время
void setTime(const PITime & t) {hours = t.hours; minutes = t.minutes; seconds = t.seconds; milliseconds = t.milliseconds;}
//! \~english Sum operator
//! \~russian Оператор сложения
void operator +=(const PIDateTime & d1) {year += d1.year; month += d1.month; day += d1.day; hours += d1.hours; minutes += d1.minutes; seconds += d1.seconds; normalize();}
//! \~english Subtract operator
//! \~russian Оператор вычитания
void operator -=(const PIDateTime & d1) {year -= d1.year; month -= d1.month; day -= d1.day; hours -= d1.hours; minutes -= d1.minutes; seconds -= d1.seconds; normalize();}
//! \~english Construct %PIDateTime from seconds since 1 Jan 1970
//! \~russian Создает %PIDateTime из секунд от 1 Янв 1970
static PIDateTime fromSecondSinceEpoch(const time_t sec);
//! \~english Construct %PIDateTime from %PISystemTime
//! \~russian Создает %PIDateTime из %PISystemTime
static PIDateTime fromSystemTime(const PISystemTime & st) {PIDateTime dt = fromSecondSinceEpoch(st.seconds); dt.milliseconds = piClampi(st.nanoseconds / 1000000, 0, 999); return dt;}
//! \~english Returns current date and time
//! \~russian Возвращает текущую дату и время
static PIDateTime current();
//! \~english Year
//! \~russian Год
int year;
//! \~english Month, 1-12
//! \~russian Месяц, 1-12
int month;
//! \~english Day, 1-31
//! \~russian День, 1-31
int day;
//! \~english Hour, 0-23
//! \~russian Час, 0-23
int hours;
//! \~english Minutes, 0-59
//! \~russian Минуты, 0-59
int minutes;
//! \~english Seconds, 0-59
//! \~russian Секунды, 0-59
int seconds;
//! \~english Milliseconds, 0-999
//! \~russian Миллисекунды, 0-999
int milliseconds;
};
//! \~english Sum operator
//! \~russian Оператор сложения
inline PIDateTime operator +(const PIDateTime & d0, const PIDateTime & d1) {PIDateTime td = d0; td += d1; return td.normalized();}
//! \~english Subtract operator
//! \~russian Оператор вычитания
inline PIDateTime operator -(const PIDateTime & d0, const PIDateTime & d1) {PIDateTime td = d0; td -= d1; return td.normalized();}
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator ==(const PIDateTime & t0, const PIDateTime & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator <(const PIDateTime & t0, const PIDateTime & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
PIP_EXPORT bool operator >(const PIDateTime & t0, const PIDateTime & t1);
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator !=(const PIDateTime & t0, const PIDateTime & t1) {return !(t0 == t1);}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator <=(const PIDateTime & t0, const PIDateTime & t1) {return !(t0 > t1);}
//! \~english Compare operator
//! \~russian Оператор сравнения
inline bool operator >=(const PIDateTime & t0, const PIDateTime & t1) {return !(t0 < t1);}
//! \relatesalso PIByteArray
//! \~english Store operator
//! \~russian Оператор сохранения
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;}
//! \relatesalso PIByteArray
//! \~english Restore operator
//! \~russian Оператор извлечения
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

View File

@@ -244,104 +244,104 @@ public:
pivCustom /** Custom */ = 0xFF
};
//! Empty constructor, \a type() will be set to \a Invalid
//! Construct \a pivInvalid %PIVariant
PIVariant();
PIVariant(const PIVariant & v);
PIVariant(PIVariant && v);
//! Constructs variant from string
//! Constructs %PIVariant from string
PIVariant(const char * v) {initType(PIString(v));}
//! Constructs variant from boolean
//! Constructs %PIVariant from boolean
PIVariant(const bool v) {initType(v);}
//! Constructs variant from char
//! Constructs %PIVariant from char
PIVariant(const char v) {initType(v);}
//! Constructs variant from integer
//! Constructs %PIVariant from integer
PIVariant(const uchar v) {initType(v);}
//! Constructs variant from integer
//! Constructs %PIVariant from integer
PIVariant(const short v) {initType(v);}
//! Constructs variant from integer
//! Constructs %PIVariant from integer
PIVariant(const ushort v) {initType(v);}
//! Constructs variant from integer
//! Constructs %PIVariant from integer
PIVariant(const int & v) {initType(v);}
//! Constructs variant from integer
//! Constructs %PIVariant from integer
PIVariant(const uint & v) {initType(v);}
//! Constructs variant from integer
//! Constructs %PIVariant from integer
PIVariant(const llong & v) {initType(v);}
//! Constructs variant from integer
//! Constructs %PIVariant from integer
PIVariant(const ullong & v) {initType(v);}
//! Constructs variant from float
//! Constructs %PIVariant from float
PIVariant(const float & v) {initType(v);}
//! Constructs variant from double
//! Constructs %PIVariant from double
PIVariant(const double & v) {initType(v);}
//! Constructs variant from long double
//! Constructs %PIVariant from long double
PIVariant(const ldouble & v) {initType(v);}
//! Constructs variant from bit array
//! Constructs %PIVariant from bit array
PIVariant(const PIBitArray & v) {initType(v);}
//! Constructs variant from byte array
//! Constructs %PIVariant from byte array
PIVariant(const PIByteArray & v) {initType(v);}
//! Constructs variant from string
//! Constructs %PIVariant from string
PIVariant(const PIString & v) {initType(v);}
//! Constructs variant from strings list
//! Constructs %PIVariant from strings list
PIVariant(const PIStringList & v) {initType(v);}
//! Constructs variant from time
//! Constructs %PIVariant from time
PIVariant(const PITime & v) {initType(v);}
//! Constructs variant from date
//! Constructs %PIVariant from date
PIVariant(const PIDate & v) {initType(v);}
//! Constructs variant from date and time
//! Constructs %PIVariant from date and time
PIVariant(const PIDateTime & v) {initType(v);}
//! Constructs variant from system time
//! Constructs %PIVariant from system time
PIVariant(const PISystemTime & v) {initType(v);}
//! Constructs variant from enum
//! Constructs %PIVariant from enum
PIVariant(const PIVariantTypes::Enum & v) {initType(v);}
//! Constructs variant from file
//! Constructs %PIVariant from file
PIVariant(const PIVariantTypes::File & v) {initType(v);}
//! Constructs variant from dir
//! Constructs %PIVariant from dir
PIVariant(const PIVariantTypes::Dir & v) {initType(v);}
//! Constructs variant from color
//! Constructs %PIVariant from color
PIVariant(const PIVariantTypes::Color & v) {initType(v);}
//! Constructs variant from IODevice
//! Constructs %PIVariant from IODevice
PIVariant(const PIVariantTypes::IODevice & v) {initType(v);}
//! Constructs variant from point
//! Constructs %PIVariant from point
PIVariant(const PIPointd & v) {initType(v);}
//! Constructs variant from rect
//! Constructs %PIVariant from rect
PIVariant(const PIRectd & v) {initType(v);}
//! Constructs variant from line
//! Constructs %PIVariant from line
PIVariant(const PILined & v) {initType(v);}
//! Constructs variant from MathVector
//! Constructs %PIVariant from MathVector
PIVariant(const PIMathVectord & v) {initType(v);}
//! Constructs variant from MathMatrix
//! Constructs %PIVariant from MathMatrix
PIVariant(const PIMathMatrixd & v) {initType(v);}