xref: /trunk/main/unotools/source/misc/datetime.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_unotools.hxx"
30 #include <unotools/datetime.hxx>
31 #include <tools/date.hxx>
32 #include <tools/time.hxx>
33 #include <tools/datetime.hxx>
34 
35 //.........................................................................
36 namespace utl
37 {
38 //.........................................................................
39 
40 //------------------------------------------------------------------
41 void typeConvert(const Time& _rTime, starutil::Time& _rOut)
42 {
43     _rOut.Hours = _rTime.GetHour();
44     _rOut.Minutes = _rTime.GetMin();
45     _rOut.Seconds = _rTime.GetSec();
46     _rOut.HundredthSeconds = _rTime.Get100Sec();
47 }
48 
49 //------------------------------------------------------------------
50 void typeConvert(const starutil::Time& _rTime, Time& _rOut)
51 {
52     _rOut = Time(_rTime.Hours, _rTime.Minutes, _rTime.Seconds, _rTime.HundredthSeconds);
53 }
54 
55 //------------------------------------------------------------------
56 void typeConvert(const Date& _rDate, starutil::Date& _rOut)
57 {
58     _rOut.Day = _rDate.GetDay();
59     _rOut.Month = _rDate.GetMonth();
60     _rOut.Year = _rDate.GetYear();
61 }
62 
63 //------------------------------------------------------------------
64 void typeConvert(const starutil::Date& _rDate, Date& _rOut)
65 {
66     _rOut = Date(_rDate.Day, _rDate.Month, _rDate.Year);
67 }
68 
69 //------------------------------------------------------------------
70 void typeConvert(const DateTime& _rDateTime, starutil::DateTime& _rOut)
71 {
72     _rOut.Year = _rDateTime.GetYear();
73     _rOut.Month = _rDateTime.GetMonth();
74     _rOut.Day = _rDateTime.GetDay();
75     _rOut.Hours = _rDateTime.GetHour();
76     _rOut.Minutes = _rDateTime.GetMin();
77     _rOut.Seconds = _rDateTime.GetSec();
78     _rOut.HundredthSeconds = _rDateTime.Get100Sec();
79 }
80 
81 //------------------------------------------------------------------
82 void typeConvert(const starutil::DateTime& _rDateTime, DateTime& _rOut)
83 {
84     Date aDate(_rDateTime.Day, _rDateTime.Month, _rDateTime.Year);
85     Time aTime(_rDateTime.Hours, _rDateTime.Minutes, _rDateTime.Seconds, _rDateTime.HundredthSeconds);
86     _rOut = DateTime(aDate, aTime);
87 }
88 
89 //-------------------------------------------------------------------------
90 sal_Bool    operator ==(const starutil::DateTime& _rLeft, const starutil::DateTime& _rRight)
91 {
92     return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) &&
93     ( _rLeft.Seconds == _rRight.Seconds) &&
94     ( _rLeft.Minutes == _rRight.Minutes) &&
95     ( _rLeft.Hours == _rRight.Hours) &&
96     ( _rLeft.Day == _rRight.Day) &&
97     ( _rLeft.Month == _rRight.Month) &&
98     ( _rLeft.Year == _rRight.Year) ;
99 }
100 
101 //-------------------------------------------------------------------------
102 sal_Bool    operator ==(const starutil::Date& _rLeft, const starutil::Date& _rRight)
103 {
104     return ( _rLeft.Day == _rRight.Day) &&
105     ( _rLeft.Month == _rRight.Month) &&
106     ( _rLeft.Year == _rRight.Year) ;
107 }
108 
109 //-------------------------------------------------------------------------
110 sal_Bool    operator ==(const starutil::Time& _rLeft, const starutil::Time& _rRight)
111 {
112     return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) &&
113     ( _rLeft.Seconds == _rRight.Seconds) &&
114     ( _rLeft.Minutes == _rRight.Minutes) &&
115     ( _rLeft.Hours == _rRight.Hours) ;
116 }
117 
118 //.........................................................................
119 }   // namespace utl
120 //.........................................................................
121 
122