|
|
|||
File indexing completed on 2026-09-20 09:18:51
0001 // Created on: 1993-01-04 0002 // Created by: J.P. BOUDIER - J.P. TIRAULT 0003 // Copyright (c) 1993-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _Quantity_Date_HeaderFile 0018 #define _Quantity_Date_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Handle.hxx> 0023 0024 #include <Standard_Boolean.hxx> 0025 class Quantity_Period; 0026 0027 //! This class provides services to manage date information. 0028 //! A date represents the following time intervals: 0029 //! year, month, day, hour, minute, second, 0030 //! millisecond and microsecond. 0031 //! Current time is expressed in elapsed seconds 0032 //! and microseconds beginning from 00:00 GMT, 0033 //! January 1, 1979 (zero hour). The valid date can 0034 //! only be later than this one. 0035 //! Note: a Period object gives the interval between two dates. 0036 class Quantity_Date 0037 { 0038 public: 0039 DEFINE_STANDARD_ALLOC 0040 0041 //! Constructs a default date 0042 //! (00:00 GMT, January 1, 1979 (zero hour)); use the function 0043 //! SetValues to define the required date; or 0044 Standard_EXPORT Quantity_Date(); 0045 0046 //! Constructs a date from the year yyyy, the 0047 //! month mm, the day dd, the hour hh, the minute 0048 //! mn, the second ss, the millisecond mis 0049 //! (defaulted to 0) and the microsecond mics (defaulted to 0). 0050 //! With: 0051 //! 1 <= mm <= 12 0052 //! 1 <= dd <= max number of days of <mm> 0053 //! 1979 <= yyyy 0054 //! 0 <= hh <= 23 0055 //! 0 <= mn <= 59 0056 //! 0 <= ss <= 59 0057 //! 0 <= mis <= 999 0058 //! 0 <= mics <= 999 0059 //! Exceptions 0060 //! Quantity_DateDefinitionError if mm, dd, hh, 0061 //! mn, ss, mis and mics are not the components of the valid date. 0062 Standard_EXPORT Quantity_Date(const int mm, 0063 const int dd, 0064 const int yyyy, 0065 const int hh, 0066 const int mn, 0067 const int ss, 0068 const int mis = 0, 0069 const int mics = 0); 0070 0071 //! Gets a complete Date. 0072 //! - in mm - the month, 0073 //! - in dd - the day, 0074 //! - in yyyy - the year, 0075 //! - in hh - the hour, 0076 //! - in mn - the minute, 0077 //! - in ss - the second, 0078 //! - in mis - the millisecond, and 0079 //! - in mics - the microsecond 0080 Standard_EXPORT void Values(int& mm, 0081 int& dd, 0082 int& yy, 0083 int& hh, 0084 int& mn, 0085 int& ss, 0086 int& mis, 0087 int& mics) const; 0088 0089 //! Assigns to this date the year yyyy, the month 0090 //! mm, the day dd, the hour hh, the minute mn, the 0091 //! second ss, the millisecond mis (defaulted to 0) 0092 //! and the microsecond mics (defaulted to 0). 0093 //! Exceptions 0094 //! Quantity_DateDefinitionError if mm, dd, hh, 0095 //! mn, ss, mis and mics are not components of a valid date. 0096 Standard_EXPORT void SetValues(const int mm, 0097 const int dd, 0098 const int yy, 0099 const int hh, 0100 const int mn, 0101 const int ss, 0102 const int mis = 0, 0103 const int mics = 0); 0104 0105 //! Subtracts one Date from another one to find the period 0106 //! between and returns the value. 0107 //! The result is the absolute value between the difference 0108 //! of two dates. 0109 Standard_EXPORT Quantity_Period Difference(const Quantity_Date& anOther); 0110 0111 //! Subtracts a period from a Date and returns the new Date. 0112 //! Raises an exception if the result date is anterior to 0113 //! Jan 1, 1979. 0114 Standard_EXPORT Quantity_Date Subtract(const Quantity_Period& aPeriod); 0115 0116 Quantity_Date operator-(const Quantity_Period& aPeriod) { return Subtract(aPeriod); } 0117 0118 //! Adds a Period to a Date and returns the new Date. 0119 Standard_EXPORT Quantity_Date Add(const Quantity_Period& aPeriod); 0120 0121 Quantity_Date operator+(const Quantity_Period& aPeriod) { return Add(aPeriod); } 0122 0123 //! Returns year of a Date. 0124 Standard_EXPORT int Year(); 0125 0126 //! Returns month of a Date. 0127 Standard_EXPORT int Month(); 0128 0129 //! Returns Day of a Date. 0130 Standard_EXPORT int Day(); 0131 0132 //! Returns Hour of a Date. 0133 Standard_EXPORT int Hour(); 0134 0135 //! Returns minute of a Date. 0136 Standard_EXPORT int Minute(); 0137 0138 //! Returns second of a Date. 0139 Standard_EXPORT int Second(); 0140 0141 //! Returns millisecond of a Date. 0142 Standard_EXPORT int MilliSecond(); 0143 0144 //! Returns microsecond of a Date. 0145 Standard_EXPORT int MicroSecond(); 0146 0147 //! Returns TRUE if both <me> and <other> are equal. 0148 //! This method is an alias of operator ==. 0149 constexpr bool IsEqual(const Quantity_Date& anOther) const noexcept 0150 { 0151 return (myUSec == anOther.myUSec && mySec == anOther.mySec); 0152 } 0153 0154 constexpr bool operator==(const Quantity_Date& anOther) const noexcept 0155 { 0156 return IsEqual(anOther); 0157 } 0158 0159 //! Returns TRUE if <me> is earlier than <other>. 0160 constexpr bool IsEarlier(const Quantity_Date& anOther) const noexcept 0161 { 0162 return (mySec < anOther.mySec) || (mySec == anOther.mySec && myUSec < anOther.myUSec); 0163 } 0164 0165 constexpr bool operator<(const Quantity_Date& anOther) const noexcept 0166 { 0167 return IsEarlier(anOther); 0168 } 0169 0170 //! Returns TRUE if <me> is later then <other>. 0171 constexpr bool IsLater(const Quantity_Date& anOther) const noexcept 0172 { 0173 return (mySec > anOther.mySec) || (mySec == anOther.mySec && myUSec > anOther.myUSec); 0174 } 0175 0176 constexpr bool operator>(const Quantity_Date& anOther) const noexcept { return IsLater(anOther); } 0177 0178 //! Checks the validity of a date - returns true if a 0179 //! date defined from the year yyyy, the month mm, 0180 //! the day dd, the hour hh, the minute mn, the 0181 //! second ss, the millisecond mis (defaulted to 0) 0182 //! and the microsecond mics (defaulted to 0) is valid. 0183 //! A date must satisfy the conditions above: 0184 //! - yyyy is greater than or equal to 1979, 0185 //! - mm lies within the range [1, 12] (with 1 0186 //! corresponding to January and 12 to December), 0187 //! - dd lies within a valid range for the month mm 0188 //! (from 1 to 28, 29, 30 or 31 depending on 0189 //! mm and whether yyyy is a leap year or not), 0190 //! - hh lies within the range [0, 23], 0191 //! - mn lies within the range [0, 59], 0192 //! - ss lies within the range [0, 59], 0193 //! - mis lies within the range [0, 999], 0194 //! - mics lies within the range [0, 999].C 0195 Standard_EXPORT static bool IsValid(const int mm, 0196 const int dd, 0197 const int yy, 0198 const int hh, 0199 const int mn, 0200 const int ss, 0201 const int mis = 0, 0202 const int mics = 0); 0203 0204 //! Returns true if a year is a leap year. 0205 //! The leap years are divisible by 4 and not by 100 except 0206 //! the years divisible by 400. 0207 static constexpr bool IsLeap(const int yy) noexcept 0208 { 0209 return ((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400) == 0; 0210 } 0211 0212 private: 0213 int mySec; 0214 int myUSec; 0215 }; 0216 0217 #endif // _Quantity_Date_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|