/* * Copyright (C) 2005-2018 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later * See LICENSES/README.md for more information. */ #pragma once #include "utils/IArchivable.h" #include "utils/XTimeUtils.h" #include #include "PlatformDefs.h" /*! \brief TIME_FORMAT enum/bitmask used for formatting time strings Note the use of bitmasking, e.g. TIME_FORMAT_HH_MM_SS = TIME_FORMAT_HH | TIME_FORMAT_MM | TIME_FORMAT_SS \sa StringUtils::SecondsToTimeString \note For InfoLabels use the equivalent value listed (bold) on the description of each enum value. \noteExample: 3661 seconds => h=1, hh=01, m=1, mm=01, ss=01, hours=1, mins=61, secs=3661


@skinning_v18 **[Infolabels Updated]** Added secs, mins, hours (total time) and **m** as possible formats for InfoLabels that support the definition of a time format. Examples are: - \link Player_SeekOffset_format `Player.SeekOffset(format)`\endlink - \link Player_TimeRemaining_format `Player.TimeRemaining(format)`\endlink - \link Player_Time_format `Player.Time(format)`\endlink - \link Player_Duration_format `Player.Duration(format)`\endlink - \link Player_FinishTime_format `Player.FinishTime(format)`\endlink - \link Player_StartTime_format `Player.StartTime(format)` \endlink - \link Player_SeekNumeric_format `Player.SeekNumeric(format)`\endlink - \link ListItem_Duration_format `ListItem.Duration(format)`\endlink - \link PVR_EpgEventDuration_format `PVR.EpgEventDuration(format)`\endlink - \link PVR_EpgEventElapsedTime_format `PVR.EpgEventElapsedTime(format)`\endlink - \link PVR_EpgEventRemainingTime_format `PVR.EpgEventRemainingTime(format)`\endlink - \link PVR_EpgEventSeekTime_format `PVR.EpgEventSeekTime(format)`\endlink - \link PVR_EpgEventFinishTime_format `PVR.EpgEventFinishTime(format)`\endlink - \link PVR_TimeShiftStart_format `PVR.TimeShiftStart(format)`\endlink - \link PVR_TimeShiftEnd_format `PVR.TimeShiftEnd(format)`\endlink - \link PVR_TimeShiftCur_format `PVR.TimeShiftCur(format)`\endlink - \link PVR_TimeShiftOffset_format `PVR.TimeShiftOffset(format)`\endlink - \link PVR_TimeshiftProgressDuration_format `PVR.TimeshiftProgressDuration(format)`\endlink - \link PVR_TimeshiftProgressEndTime `PVR.TimeshiftProgressEndTime`\endlink - \link PVR_TimeshiftProgressEndTime_format `PVR.TimeshiftProgressEndTime(format)`\endlink - \link ListItem_NextDuration_format `ListItem.NextDuration(format)` \endlink

*/ enum TIME_FORMAT { TIME_FORMAT_GUESS = 0, ///< usually used as the fallback value if the format value is empty TIME_FORMAT_SS = 1, ///< ss - seconds only TIME_FORMAT_MM = 2, ///< mm - minutes only (2-digit) TIME_FORMAT_MM_SS = 3, ///< mm:ss - minutes and seconds TIME_FORMAT_HH = 4, ///< hh - hours only (2-digit) TIME_FORMAT_HH_SS = 5, ///< hh:ss - hours and seconds (this is not particularly useful) TIME_FORMAT_HH_MM = 6, ///< hh:mm - hours and minutes TIME_FORMAT_HH_MM_SS = 7, ///< hh:mm:ss - hours, minutes and seconds TIME_FORMAT_XX = 8, ///< xx - returns AM/PM for a 12-hour clock TIME_FORMAT_HH_MM_XX = 14, ///< hh:mm xx - returns hours and minutes in a 12-hour clock format (AM/PM) TIME_FORMAT_HH_MM_SS_XX = 15, ///< hh:mm:ss xx - returns hours (2-digit), minutes and seconds in a 12-hour clock format (AM/PM) TIME_FORMAT_H = 16, ///< h - hours only (1-digit) TIME_FORMAT_H_MM_SS = 19, ///< hh:mm:ss - hours, minutes and seconds TIME_FORMAT_H_MM_SS_XX = 27, ///< hh:mm:ss xx - returns hours (1-digit), minutes and seconds in a 12-hour clock format (AM/PM) TIME_FORMAT_SECS = 32, ///< secs - total time in seconds TIME_FORMAT_MINS = 64, ///< mins - total time in minutes TIME_FORMAT_HOURS = 128, ///< hours - total time in hours TIME_FORMAT_M = 256 ///< m - minutes only (1-digit) }; class CDateTime; class CDateTimeSpan { public: CDateTimeSpan(); CDateTimeSpan(const CDateTimeSpan& span); CDateTimeSpan(int day, int hour, int minute, int second); bool operator >(const CDateTimeSpan& right) const; bool operator >=(const CDateTimeSpan& right) const; bool operator <(const CDateTimeSpan& right) const; bool operator <=(const CDateTimeSpan& right) const; bool operator ==(const CDateTimeSpan& right) const; bool operator !=(const CDateTimeSpan& right) const; CDateTimeSpan operator +(const CDateTimeSpan& right) const; CDateTimeSpan operator -(const CDateTimeSpan& right) const; const CDateTimeSpan& operator +=(const CDateTimeSpan& right); const CDateTimeSpan& operator -=(const CDateTimeSpan& right); void SetDateTimeSpan(int day, int hour, int minute, int second); void SetFromPeriod(const std::string &period); void SetFromTimeString(const std::string& time); int GetDays() const; int GetHours() const; int GetMinutes() const; int GetSeconds() const; int GetSecondsTotal() const; private: void ToLargeInt(LARGE_INTEGER& time) const; void FromLargeInt(const LARGE_INTEGER& time); private: KODI::TIME::FileTime m_timeSpan; friend class CDateTime; }; /// \brief DateTime class, which uses FileTime as it's base. class CDateTime final : public IArchivable { public: CDateTime(); CDateTime(const CDateTime& time); explicit CDateTime(const KODI::TIME::SystemTime& time); explicit CDateTime(const KODI::TIME::FileTime& time); explicit CDateTime(const time_t& time); explicit CDateTime(const tm& time); CDateTime(int year, int month, int day, int hour, int minute, int second); static CDateTime GetCurrentDateTime(); static CDateTime GetUTCDateTime(); static int MonthStringToMonthNum(const std::string& month); static CDateTime FromDBDateTime(const std::string &dateTime); static CDateTime FromDateString(const std::string &date); static CDateTime FromDBDate(const std::string &date); static CDateTime FromDBTime(const std::string &time); static CDateTime FromW3CDate(const std::string &date); static CDateTime FromW3CDateTime(const std::string &date, bool ignoreTimezone = false); static CDateTime FromUTCDateTime(const CDateTime &dateTime); static CDateTime FromUTCDateTime(const time_t &dateTime); static CDateTime FromRFC1123DateTime(const std::string &dateTime); const CDateTime& operator=(const KODI::TIME::SystemTime& right); const CDateTime& operator=(const KODI::TIME::FileTime& right); const CDateTime& operator =(const time_t& right); const CDateTime& operator =(const tm& right); bool operator >(const CDateTime& right) const; bool operator >=(const CDateTime& right) const; bool operator <(const CDateTime& right) const; bool operator <=(const CDateTime& right) const; bool operator ==(const CDateTime& right) const; bool operator !=(const CDateTime& right) const; bool operator>(const KODI::TIME::FileTime& right) const; bool operator>=(const KODI::TIME::FileTime& right) const; bool operator<(const KODI::TIME::FileTime& right) const; bool operator<=(const KODI::TIME::FileTime& right) const; bool operator==(const KODI::TIME::FileTime& right) const; bool operator!=(const KODI::TIME::FileTime& right) const; bool operator>(const KODI::TIME::SystemTime& right) const; bool operator>=(const KODI::TIME::SystemTime& right) const; bool operator<(const KODI::TIME::SystemTime& right) const; bool operator<=(const KODI::TIME::SystemTime& right) const; bool operator==(const KODI::TIME::SystemTime& right) const; bool operator!=(const KODI::TIME::SystemTime& right) const; bool operator >(const time_t& right) const; bool operator >=(const time_t& right) const; bool operator <(const time_t& right) const; bool operator <=(const time_t& right) const; bool operator ==(const time_t& right) const; bool operator !=(const time_t& right) const; bool operator >(const tm& right) const; bool operator >=(const tm& right) const; bool operator <(const tm& right) const; bool operator <=(const tm& right) const; bool operator ==(const tm& right) const; bool operator !=(const tm& right) const; CDateTime operator +(const CDateTimeSpan& right) const; CDateTime operator -(const CDateTimeSpan& right) const; const CDateTime& operator +=(const CDateTimeSpan& right); const CDateTime& operator -=(const CDateTimeSpan& right); CDateTimeSpan operator -(const CDateTime& right) const; operator KODI::TIME::FileTime() const; void Archive(CArchive& ar) override; void Reset(); int GetDay() const; int GetMonth() const; int GetYear() const; int GetHour() const; int GetMinute() const; int GetSecond() const; int GetDayOfWeek() const; int GetMinuteOfDay() const; bool SetDateTime(int year, int month, int day, int hour, int minute, int second); bool SetDate(int year, int month, int day); bool SetTime(int hour, int minute, int second); bool SetFromDateString(const std::string &date); bool SetFromDBDate(const std::string &date); bool SetFromDBTime(const std::string &time); bool SetFromW3CDate(const std::string &date); bool SetFromW3CDateTime(const std::string &date, bool ignoreTimezone = false); bool SetFromUTCDateTime(const CDateTime &dateTime); bool SetFromUTCDateTime(const time_t &dateTime); bool SetFromRFC1123DateTime(const std::string &dateTime); /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS \sa GetAsDBDateTime() */ bool SetFromDBDateTime(const std::string &dateTime); void GetAsSystemTime(KODI::TIME::SystemTime& time) const; void GetAsTime(time_t& time) const; void GetAsTm(tm& time) const; void GetAsTimeStamp(KODI::TIME::FileTime& time) const; CDateTime GetAsUTCDateTime() const; std::string GetAsSaveString() const; std::string GetAsDBDateTime() const; std::string GetAsDBDate() const; std::string GetAsDBTime() const; std::string GetAsLocalizedDate(bool longDate=false) const; std::string GetAsLocalizedDate(const std::string &strFormat) const; std::string GetAsLocalizedTime(const std::string &format, bool withSeconds=true) const; std::string GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const; std::string GetAsLocalizedTime(TIME_FORMAT format, bool withSeconds = false) const; std::string GetAsRFC1123DateTime() const; std::string GetAsW3CDate() const; std::string GetAsW3CDateTime(bool asUtc = false) const; void SetValid(bool yesNo); bool IsValid() const; static void ResetTimezoneBias(void); static CDateTimeSpan GetTimezoneBias(void); private: bool ToFileTime(const KODI::TIME::SystemTime& time, KODI::TIME::FileTime& fileTime) const; bool ToFileTime(const time_t& time, KODI::TIME::FileTime& fileTime) const; bool ToFileTime(const tm& time, KODI::TIME::FileTime& fileTime) const; void ToLargeInt(LARGE_INTEGER& time) const; void FromLargeInt(const LARGE_INTEGER& time); private: KODI::TIME::FileTime m_time; typedef enum _STATE { invalid=0, valid } STATE; STATE m_state; };