0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / Quantity / Quantity_Date.hxx
CommitLineData
42cf5bc1 1// Created on: 1993-01-04
2// Created by: J.P. BOUDIER - J.P. TIRAULT
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Quantity_Date_HeaderFile
18#define _Quantity_Date_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <Standard_Integer.hxx>
25#include <Standard_Boolean.hxx>
26class Quantity_DateDefinitionError;
27class Standard_OutOfRange;
28class Quantity_Period;
29
42cf5bc1 30//! This class provides services to manage date information.
31//! A date represents the following time intervals:
32//! year, month, day, hour, minute, second,
33//! millisecond and microsecond.
34//! Current time is expressed in elapsed seconds
35//! and microseconds beginning from 00:00 GMT,
36//! January 1, 1979 (zero hour). The valid date can
37//! only be later than this one.
38//! Note: a Period object gives the interval between two dates.
39class Quantity_Date
40{
41public:
42
43 DEFINE_STANDARD_ALLOC
44
42cf5bc1 45 //! Constructs a default date
46 //! (00:00 GMT, January 1, 1979 (zero hour)); use the function
47 //! SetValues to define the required date; or
48 Standard_EXPORT Quantity_Date();
49
50 //! Constructs a date from the year yyyy, the
51 //! month mm, the day dd, the hour hh, the minute
52 //! mn, the second ss, the millisecond mis
53 //! (defaulted to 0) and the microsecond mics (defaulted to 0)..
54 //! With: 1 <= mm <= 12
55 //! 1 <= dd <= max number of days of <mm>
56 //! 1979 <= yyyy
57 //! 0 <= hh <= 23
58 //! 0 <= mn <= 59
59 //! 0 <= ss <= 59
60 //! 0 <= mis <= 999
61 //! 0 <= mics <= 999
62 //! Exceptions
63 //! Quantity_DateDefinitionError if mm, dd, hh,
64 //! mn, ss, mis and mics are not the components of the valid date.
65 Standard_EXPORT Quantity_Date(const Standard_Integer mm, const Standard_Integer dd, const Standard_Integer yyyy, const Standard_Integer hh, const Standard_Integer mn, const Standard_Integer ss, const Standard_Integer mis = 0, const Standard_Integer mics = 0);
66
67 //! Gets a complete Date.
68 //! - in mm - the month,
69 //! - in dd - the day,
70 //! - in yyyy - the year,
71 //! - in hh - the hour,
72 //! - in mn - the minute,
73 //! - in ss - the second,
74 //! - in mis - the millisecond, and
75 //! - in mics - the microsecond
76 Standard_EXPORT void Values (Standard_Integer& mm, Standard_Integer& dd, Standard_Integer& yy, Standard_Integer& hh, Standard_Integer& mn, Standard_Integer& ss, Standard_Integer& mis, Standard_Integer& mics) const;
77
78 //! Assigns to this date the year yyyy, the month
79 //! mm, the day dd, the hour hh, the minute mn, the
80 //! second ss, the millisecond mis (defaulted to 0)
81 //! and the microsecond mics (defaulted to 0).
82 //! Exceptions
83 //! Quantity_DateDefinitionError if mm, dd, hh,
84 //! mn, ss, mis and mics are not components of a valid date.
85 Standard_EXPORT void SetValues (const Standard_Integer mm, const Standard_Integer dd, const Standard_Integer yy, const Standard_Integer hh, const Standard_Integer mn, const Standard_Integer ss, const Standard_Integer mis = 0, const Standard_Integer mics = 0);
86
87 //! Subtracts one Date from another one to find the period
88 //! between and returns the value.
89 //! The result is the absolute value between the difference
90 //! of two dates.
91 Standard_EXPORT Quantity_Period Difference (const Quantity_Date& anOther);
92
93 //! Subtracts a period from a Date and returns the new Date.
94 //! Raises an exception if the result date is anterior to
95 //! Jan 1, 1979.
96 Standard_EXPORT Quantity_Date Subtract (const Quantity_Period& aPeriod);
97Quantity_Date operator - (const Quantity_Period& aPeriod)
98{
99 return Subtract(aPeriod);
100}
101
102 //! Adds a Period to a Date and returns the new Date.
103 Standard_EXPORT Quantity_Date Add (const Quantity_Period& aPeriod);
104Quantity_Date operator + (const Quantity_Period& aPeriod)
105{
106 return Add(aPeriod);
107}
108
109 //! Returns year of a Date.
110 Standard_EXPORT Standard_Integer Year();
111
112 //! Returns month of a Date.
113 Standard_EXPORT Standard_Integer Month();
114
115 //! Returns Day of a Date.
116 Standard_EXPORT Standard_Integer Day();
117
118 //! Returns Hour of a Date.
119 Standard_EXPORT Standard_Integer Hour();
120
121 //! Returns minute of a Date.
122 Standard_EXPORT Standard_Integer Minute();
123
124 //! Returns seconde of a Date.
125 Standard_EXPORT Standard_Integer Second();
126
127 //! Returns millisecond of a Date.
128 Standard_EXPORT Standard_Integer MilliSecond();
129
130 //! Returns microsecond of a Date.
131 Standard_EXPORT Standard_Integer MicroSecond();
132
133 //! Returns TRUE if both <me> and <other> are equal.
134 //! This method is an alias of operator ==.
135 Standard_EXPORT Standard_Boolean IsEqual (const Quantity_Date& anOther) const;
136Standard_Boolean operator == (const Quantity_Date& anOther) const
137{
138 return IsEqual(anOther);
139}
140
141 //! Returns TRUE if <me> is earlier than <other>.
142 Standard_EXPORT Standard_Boolean IsEarlier (const Quantity_Date& anOther) const;
143Standard_Boolean operator < (const Quantity_Date& anOther) const
144{
145 return IsEarlier(anOther);
146}
147
148 //! Returns TRUE if <me> is later then <other>.
149 Standard_EXPORT Standard_Boolean IsLater (const Quantity_Date& anOther) const;
150Standard_Boolean operator > (const Quantity_Date& anOther) const
151{
152 return IsLater(anOther);
153}
154
155 //! Checks the validity of a date - returns true if a
156 //! date defined from the year yyyy, the month mm,
157 //! the day dd, the hour hh, the minute mn, the
158 //! second ss, the millisecond mis (defaulted to 0)
159 //! and the microsecond mics (defaulted to 0) is valid.
160 //! A date must satisfy the conditions above:
161 //! - yyyy is greater than or equal to 1979,
162 //! - mm lies within the range [1, 12] (with 1
163 //! corresponding to January and 12 to December),
164 //! - dd lies within a valid range for the month mm
165 //! (from 1 to 28, 29, 30 or 31 depending on
166 //! mm and whether yyyy is a leap year or not),
167 //! - hh lies within the range [0, 23],
168 //! - mn lies within the range [0, 59],
169 //! - ss lies within the range [0, 59],
170 //! - mis lies within the range [0, 999],
171 //! - mics lies within the range [0, 999].C
172 Standard_EXPORT static Standard_Boolean IsValid (const Standard_Integer mm, const Standard_Integer dd, const Standard_Integer yy, const Standard_Integer hh, const Standard_Integer mn, const Standard_Integer ss, const Standard_Integer mis = 0, const Standard_Integer mics = 0);
173
174 //! Returns true if a year is a leap year.
175 //! The leap years are divisable by 4 and not by 100 except
176 //! the years divisable by 400.
09324e85 177 static Standard_Boolean IsLeap (const Standard_Integer yy)
178 {
179 return ((yy % 4 == 0) && (yy % 100 != 0))
180 || (yy % 400) == 0;
181 }
42cf5bc1 182
183private:
184
42cf5bc1 185 Standard_Integer mySec;
186 Standard_Integer myUSec;
187
42cf5bc1 188};
189
42cf5bc1 190#endif // _Quantity_Date_HeaderFile