xref: /aoo41x/main/tools/source/datetime/datetime.cxx (revision 89b56da7)
1*89b56da7SAndrew Rist /**************************************************************
2*89b56da7SAndrew Rist  *
3*89b56da7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*89b56da7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*89b56da7SAndrew Rist  * distributed with this work for additional information
6*89b56da7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*89b56da7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*89b56da7SAndrew Rist  * "License"); you may not use this file except in compliance
9*89b56da7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*89b56da7SAndrew Rist  *
11*89b56da7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*89b56da7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*89b56da7SAndrew Rist  * software distributed under the License is distributed on an
15*89b56da7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*89b56da7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*89b56da7SAndrew Rist  * specific language governing permissions and limitations
18*89b56da7SAndrew Rist  * under the License.
19*89b56da7SAndrew Rist  *
20*89b56da7SAndrew Rist  *************************************************************/
21*89b56da7SAndrew Rist 
22*89b56da7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/datetime.hxx>
28cdf0e10cSrcweir #include <rtl/math.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /*************************************************************************
31cdf0e10cSrcweir |*
32cdf0e10cSrcweir |*    DateTime::IsBetween()
33cdf0e10cSrcweir |*
34cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
35cdf0e10cSrcweir |*    Ersterstellung    TH 18.05.92
36cdf0e10cSrcweir |*    Letzte Aenderung  TH 18.05.92
37cdf0e10cSrcweir |*
38cdf0e10cSrcweir *************************************************************************/
39cdf0e10cSrcweir 
IsBetween(const DateTime & rFrom,const DateTime & rTo) const40cdf0e10cSrcweir sal_Bool DateTime::IsBetween( const DateTime& rFrom,
41cdf0e10cSrcweir                           const DateTime& rTo ) const
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     if ( (*this >= rFrom) && (*this <= rTo) )
44cdf0e10cSrcweir         return sal_True;
45cdf0e10cSrcweir     else
46cdf0e10cSrcweir         return sal_False;
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /*************************************************************************
50cdf0e10cSrcweir |*
51cdf0e10cSrcweir |*    DateTime::operator >()
52cdf0e10cSrcweir |*
53cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
54cdf0e10cSrcweir |*    Ersterstellung    TH 18.05.92
55cdf0e10cSrcweir |*    Letzte Aenderung  TH 18.05.92
56cdf0e10cSrcweir |*
57cdf0e10cSrcweir *************************************************************************/
58cdf0e10cSrcweir 
operator >(const DateTime & rDateTime) const59cdf0e10cSrcweir sal_Bool DateTime::operator >( const DateTime& rDateTime ) const
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     if ( (Date::operator>( rDateTime )) ||
62cdf0e10cSrcweir          (Date::operator==( rDateTime ) && Time::operator>( rDateTime )) )
63cdf0e10cSrcweir         return sal_True;
64cdf0e10cSrcweir     else
65cdf0e10cSrcweir         return sal_False;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir /*************************************************************************
69cdf0e10cSrcweir |*
70cdf0e10cSrcweir |*    DateTime::operator <()
71cdf0e10cSrcweir |*
72cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
73cdf0e10cSrcweir |*    Ersterstellung    TH 18.05.92
74cdf0e10cSrcweir |*    Letzte Aenderung  TH 18.05.92
75cdf0e10cSrcweir |*
76cdf0e10cSrcweir *************************************************************************/
77cdf0e10cSrcweir 
operator <(const DateTime & rDateTime) const78cdf0e10cSrcweir sal_Bool DateTime::operator <( const DateTime& rDateTime ) const
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     if ( (Date::operator<( rDateTime )) ||
81cdf0e10cSrcweir          (Date::operator==( rDateTime ) && Time::operator<( rDateTime )) )
82cdf0e10cSrcweir         return sal_True;
83cdf0e10cSrcweir     else
84cdf0e10cSrcweir         return sal_False;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir /*************************************************************************
88cdf0e10cSrcweir |*
89cdf0e10cSrcweir |*    DateTime::operator >=()
90cdf0e10cSrcweir |*
91cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
92cdf0e10cSrcweir |*    Ersterstellung    TH 18.05.92
93cdf0e10cSrcweir |*    Letzte Aenderung  TH 18.05.92
94cdf0e10cSrcweir |*
95cdf0e10cSrcweir *************************************************************************/
96cdf0e10cSrcweir 
operator >=(const DateTime & rDateTime) const97cdf0e10cSrcweir sal_Bool DateTime::operator >=( const DateTime& rDateTime ) const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     if ( (Date::operator>( rDateTime )) ||
100cdf0e10cSrcweir          (Date::operator==( rDateTime ) && Time::operator>=( rDateTime )) )
101cdf0e10cSrcweir         return sal_True;
102cdf0e10cSrcweir     else
103cdf0e10cSrcweir         return sal_False;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir /*************************************************************************
107cdf0e10cSrcweir |*
108cdf0e10cSrcweir |*    DateTime::operator <=()
109cdf0e10cSrcweir |*
110cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
111cdf0e10cSrcweir |*    Ersterstellung    TH 18.05.92
112cdf0e10cSrcweir |*    Letzte Aenderung  TH 18.05.92
113cdf0e10cSrcweir |*
114cdf0e10cSrcweir *************************************************************************/
115cdf0e10cSrcweir 
operator <=(const DateTime & rDateTime) const116cdf0e10cSrcweir sal_Bool DateTime::operator <=( const DateTime& rDateTime ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     if ( (Date::operator<( rDateTime )) ||
119cdf0e10cSrcweir          (Date::operator==( rDateTime ) && Time::operator<=( rDateTime )) )
120cdf0e10cSrcweir         return sal_True;
121cdf0e10cSrcweir     else
122cdf0e10cSrcweir         return sal_False;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir /*************************************************************************
126cdf0e10cSrcweir |*
127cdf0e10cSrcweir |*    DateTime::GetSecFromDateTime()
128cdf0e10cSrcweir |*
129cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
130cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
131cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
132cdf0e10cSrcweir |*
133cdf0e10cSrcweir *************************************************************************/
134cdf0e10cSrcweir 
GetSecFromDateTime(const Date & rDate) const135cdf0e10cSrcweir long DateTime::GetSecFromDateTime( const Date& rDate ) const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     if ( Date::operator<( rDate ) )
138cdf0e10cSrcweir         return 0;
139cdf0e10cSrcweir     else
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         long nSec = Date( *this ) - rDate;
142cdf0e10cSrcweir         nSec *= 24UL*60*60;
143cdf0e10cSrcweir         long nHour = GetHour();
144cdf0e10cSrcweir         long nMin  = GetMin();
145cdf0e10cSrcweir         nSec += (nHour*3600)+(nMin*60)+GetSec();
146cdf0e10cSrcweir         return nSec;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir /*************************************************************************
151cdf0e10cSrcweir |*
152cdf0e10cSrcweir |*    DateTime::GetSecFromDateTime()
153cdf0e10cSrcweir |*
154cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
155cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
156cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
157cdf0e10cSrcweir |*
158cdf0e10cSrcweir *************************************************************************/
159cdf0e10cSrcweir 
MakeDateTimeFromSec(const Date & rDate,sal_uIntPtr nSec)160cdf0e10cSrcweir void DateTime::MakeDateTimeFromSec( const Date& rDate, sal_uIntPtr nSec )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     long nDays = nSec / (24UL*60*60);
163cdf0e10cSrcweir 	((Date*)this)->operator=( rDate );
164cdf0e10cSrcweir     nSec -= nDays * (24UL*60*60);
165cdf0e10cSrcweir 	sal_uInt16 nMin = (sal_uInt16)(nSec / 60);
166cdf0e10cSrcweir 	nSec -= nMin * 60;
167cdf0e10cSrcweir     ((Time*)this)->operator=( Time( 0, nMin, (sal_uInt16)nSec ) );
168cdf0e10cSrcweir     operator+=( nDays );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir /*************************************************************************
172cdf0e10cSrcweir |*
173cdf0e10cSrcweir |*    DateTime::operator +=()
174cdf0e10cSrcweir |*
175cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
176cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
177cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
178cdf0e10cSrcweir |*
179cdf0e10cSrcweir *************************************************************************/
180cdf0e10cSrcweir 
operator +=(const Time & rTime)181cdf0e10cSrcweir DateTime& DateTime::operator +=( const Time& rTime )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     Time aTime = *this;
184cdf0e10cSrcweir     aTime += rTime;
185cdf0e10cSrcweir     sal_uInt16 nHours = aTime.GetHour();
186cdf0e10cSrcweir     if ( aTime.GetTime() > 0 )
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir         while ( nHours >= 24 )
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             Date::operator++();
191cdf0e10cSrcweir             nHours -= 24;
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir         aTime.SetHour( nHours );
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir     else if ( aTime.GetTime() != 0 )
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         while ( nHours >= 24 )
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir             Date::operator--();
200cdf0e10cSrcweir             nHours -= 24;
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir         Date::operator--();
203cdf0e10cSrcweir         aTime = Time( 24, 0, 0 )+aTime;
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir     Time::operator=( aTime );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     return *this;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir /*************************************************************************
211cdf0e10cSrcweir |*
212cdf0e10cSrcweir |*    DateTime::operator -=()
213cdf0e10cSrcweir |*
214cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
215cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
216cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
217cdf0e10cSrcweir |*
218cdf0e10cSrcweir *************************************************************************/
219cdf0e10cSrcweir 
operator -=(const Time & rTime)220cdf0e10cSrcweir DateTime& DateTime::operator -=( const Time& rTime )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     Time aTime = *this;
223cdf0e10cSrcweir     aTime -= rTime;
224cdf0e10cSrcweir     sal_uInt16 nHours = aTime.GetHour();
225cdf0e10cSrcweir     if ( aTime.GetTime() > 0 )
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         while ( nHours >= 24 )
228cdf0e10cSrcweir         {
229cdf0e10cSrcweir             Date::operator++();
230cdf0e10cSrcweir             nHours -= 24;
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir         aTime.SetHour( nHours );
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir     else if ( aTime.GetTime() != 0 )
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir         while ( nHours >= 24 )
237cdf0e10cSrcweir         {
238cdf0e10cSrcweir             Date::operator--();
239cdf0e10cSrcweir             nHours -= 24;
240cdf0e10cSrcweir         }
241cdf0e10cSrcweir         Date::operator--();
242cdf0e10cSrcweir         aTime = Time( 24, 0, 0 )+aTime;
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir     Time::operator=( aTime );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     return *this;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir /*************************************************************************
250cdf0e10cSrcweir |*
251cdf0e10cSrcweir |*    DateTime::operator+()
252cdf0e10cSrcweir |*
253cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
254cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
255cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
256cdf0e10cSrcweir |*
257cdf0e10cSrcweir *************************************************************************/
258cdf0e10cSrcweir 
operator +(const DateTime & rDateTime,long nDays)259cdf0e10cSrcweir DateTime operator +( const DateTime& rDateTime, long nDays )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     DateTime aDateTime( rDateTime );
262cdf0e10cSrcweir     aDateTime += nDays;
263cdf0e10cSrcweir     return aDateTime;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir /*************************************************************************
267cdf0e10cSrcweir |*
268cdf0e10cSrcweir |*    DateTime::operator-()
269cdf0e10cSrcweir |*
270cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
271cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
272cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
273cdf0e10cSrcweir |*
274cdf0e10cSrcweir *************************************************************************/
275cdf0e10cSrcweir 
operator -(const DateTime & rDateTime,long nDays)276cdf0e10cSrcweir DateTime operator -( const DateTime& rDateTime, long nDays )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     DateTime aDateTime( rDateTime );
279cdf0e10cSrcweir     aDateTime -= nDays;
280cdf0e10cSrcweir     return aDateTime;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir /*************************************************************************
284cdf0e10cSrcweir |*
285cdf0e10cSrcweir |*    DateTime::operator+()
286cdf0e10cSrcweir |*
287cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
288cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
289cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
290cdf0e10cSrcweir |*
291cdf0e10cSrcweir *************************************************************************/
292cdf0e10cSrcweir 
operator +(const DateTime & rDateTime,const Time & rTime)293cdf0e10cSrcweir DateTime operator +( const DateTime& rDateTime, const Time& rTime )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir     DateTime aDateTime( rDateTime );
296cdf0e10cSrcweir     aDateTime += rTime;
297cdf0e10cSrcweir     return aDateTime;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir /*************************************************************************
301cdf0e10cSrcweir |*
302cdf0e10cSrcweir |*    DateTime::operator-()
303cdf0e10cSrcweir |*
304cdf0e10cSrcweir |*    Beschreibung      DATETIME.SDW
305cdf0e10cSrcweir |*    Ersterstellung    TH 02.10.96
306cdf0e10cSrcweir |*    Letzte Aenderung  TH 02.10.96
307cdf0e10cSrcweir |*
308cdf0e10cSrcweir *************************************************************************/
309cdf0e10cSrcweir 
operator -(const DateTime & rDateTime,const Time & rTime)310cdf0e10cSrcweir DateTime operator -( const DateTime& rDateTime, const Time& rTime )
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     DateTime aDateTime( rDateTime );
313cdf0e10cSrcweir     aDateTime -= rTime;
314cdf0e10cSrcweir     return aDateTime;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir /*************************************************************************
318cdf0e10cSrcweir |*
319cdf0e10cSrcweir |*    DateTime::operator +=( double )
320cdf0e10cSrcweir |*
321cdf0e10cSrcweir *************************************************************************/
322cdf0e10cSrcweir 
operator +=(double fTimeInDays)323cdf0e10cSrcweir DateTime& DateTime::operator +=( double fTimeInDays )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir 	double fInt, fFrac;
326cdf0e10cSrcweir 	if ( fTimeInDays < 0.0 )
327cdf0e10cSrcweir 	{
328cdf0e10cSrcweir 		fInt = ::rtl::math::approxCeil( fTimeInDays );
329cdf0e10cSrcweir 		fFrac = fInt <= fTimeInDays ? 0.0 : fTimeInDays - fInt;
330cdf0e10cSrcweir 	}
331cdf0e10cSrcweir 	else
332cdf0e10cSrcweir 	{
333cdf0e10cSrcweir 		fInt = ::rtl::math::approxFloor( fTimeInDays );
334cdf0e10cSrcweir 		fFrac = fInt >= fTimeInDays ? 0.0 : fTimeInDays - fInt;
335cdf0e10cSrcweir 	}
336cdf0e10cSrcweir 	Date::operator+=( long(fInt) );		// full days
337cdf0e10cSrcweir 	if ( fFrac )
338cdf0e10cSrcweir 	{
339cdf0e10cSrcweir 		Time aTime(0);	// default ctor calls system time, we don't need that
340cdf0e10cSrcweir 		fFrac *= 24UL * 60 * 60 * 1000;		// time expressed in milliseconds
341cdf0e10cSrcweir 		aTime.MakeTimeFromMS( long(fFrac) );	// method handles negative ms
342cdf0e10cSrcweir 		operator+=( aTime );
343cdf0e10cSrcweir 	}
344cdf0e10cSrcweir 	return *this;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir /*************************************************************************
348cdf0e10cSrcweir |*
349cdf0e10cSrcweir |*    DateTime::operator +( double )
350cdf0e10cSrcweir |*
351cdf0e10cSrcweir *************************************************************************/
352cdf0e10cSrcweir 
operator +(const DateTime & rDateTime,double fTimeInDays)353cdf0e10cSrcweir DateTime operator +( const DateTime& rDateTime, double fTimeInDays )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir     DateTime aDateTime( rDateTime );
356cdf0e10cSrcweir 	aDateTime += fTimeInDays;
357cdf0e10cSrcweir 	return aDateTime;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
360cdf0e10cSrcweir /*************************************************************************
361cdf0e10cSrcweir |*
362cdf0e10cSrcweir |*    DateTime::operator -()
363cdf0e10cSrcweir |*
364cdf0e10cSrcweir *************************************************************************/
365cdf0e10cSrcweir 
operator -(const DateTime & rDateTime1,const DateTime & rDateTime2)366cdf0e10cSrcweir double operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir 	long nDays = (const Date&) rDateTime1 - (const Date&) rDateTime2;
369cdf0e10cSrcweir 	long nTime = rDateTime1.GetMSFromTime() - rDateTime2.GetMSFromTime();
370cdf0e10cSrcweir 	if ( nTime )
371cdf0e10cSrcweir 	{
372cdf0e10cSrcweir 		double fTime = double(nTime);
373cdf0e10cSrcweir 		fTime /= 24UL * 60 * 60 * 1000;	// convert from milliseconds to fraction
374cdf0e10cSrcweir 		if ( nDays < 0 && fTime > 0.0 )
375cdf0e10cSrcweir 			fTime = 1.0 - fTime;
376cdf0e10cSrcweir 		return double(nDays) + fTime;
377cdf0e10cSrcweir 	}
378cdf0e10cSrcweir 	return double(nDays);
379cdf0e10cSrcweir }
380cdf0e10cSrcweir 
GetWin32FileDateTime(sal_uInt32 & rLower,sal_uInt32 & rUpper)381cdf0e10cSrcweir void DateTime::GetWin32FileDateTime( sal_uInt32 & rLower, sal_uInt32 & rUpper )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     const sal_Int64 a100nPerSecond = SAL_CONST_INT64( 10000000 );
384cdf0e10cSrcweir     const sal_Int64 a100nPerDay = a100nPerSecond * sal_Int64( 60 * 60 * 24 );
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     sal_Int64 nYears = GetYear() - 1601;
387cdf0e10cSrcweir     sal_Int64 nDays =
388cdf0e10cSrcweir         nYears * 365 +
389cdf0e10cSrcweir         nYears / 4 - nYears / 100 + nYears / 400 +
390cdf0e10cSrcweir         GetDayOfYear() - 1;
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     sal_Int64 aTime =
393cdf0e10cSrcweir         a100nPerDay * nDays +
394cdf0e10cSrcweir         a100nPerSecond * (
395cdf0e10cSrcweir                 sal_Int64( GetSec() ) +
396cdf0e10cSrcweir                 60 * sal_Int64( GetMin() ) +
397cdf0e10cSrcweir                 60 * 60 * sal_Int64( GetHour() ) );
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     rLower = sal_uInt32( aTime % SAL_CONST_UINT64( 0x100000000 ) );
400cdf0e10cSrcweir     rUpper = sal_uInt32( aTime / SAL_CONST_UINT64( 0x100000000 ) );
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
CreateFromWin32FileDateTime(const sal_uInt32 & rLower,const sal_uInt32 & rUpper)403cdf0e10cSrcweir DateTime DateTime::CreateFromWin32FileDateTime( const sal_uInt32 & rLower, const sal_uInt32 & rUpper )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir     const sal_Int64 a100nPerSecond = SAL_CONST_INT64( 10000000 );
406cdf0e10cSrcweir     const sal_Int64 a100nPerDay = a100nPerSecond * sal_Int64( 60 * 60 * 24 );
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     sal_Int64 aTime = sal_Int64(
409cdf0e10cSrcweir             sal_uInt64( rUpper ) * SAL_CONST_UINT64( 0x100000000 ) +
410cdf0e10cSrcweir             sal_uInt64( rLower ) );
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     sal_Int64 nDays = aTime / a100nPerDay;
413cdf0e10cSrcweir     sal_Int64 nYears =
414cdf0e10cSrcweir         ( nDays -
415cdf0e10cSrcweir           ( nDays / ( 4 * 365 ) ) +
416cdf0e10cSrcweir           ( nDays / ( 100 * 365 ) ) -
417cdf0e10cSrcweir           ( nDays / ( 400 * 365 ) ) ) / 365;
418cdf0e10cSrcweir     nDays -= nYears * 365 + nYears / 4 - nYears / 100 + nYears / 400;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir     sal_uInt16 nMonths = 0;
421cdf0e10cSrcweir     for( sal_Int64 nDaysCount = nDays; nDaysCount >= 0; )
422cdf0e10cSrcweir     {
423cdf0e10cSrcweir         nDays = nDaysCount;
424cdf0e10cSrcweir         nMonths ++;
425cdf0e10cSrcweir         nDaysCount -= Date(
426cdf0e10cSrcweir             1, nMonths, sal::static_int_cast< sal_uInt16 >(1601 + nYears) ).
427cdf0e10cSrcweir             GetDaysInMonth();
428cdf0e10cSrcweir     }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     Date _aDate(
431cdf0e10cSrcweir         (sal_uInt16)( nDays + 1 ), nMonths,
432cdf0e10cSrcweir         sal::static_int_cast< sal_uInt16 >(nYears + 1601) );
433cdf0e10cSrcweir     Time _aTime( sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 * 60 ) ) % sal_Int64( 24 ) ),
434cdf0e10cSrcweir             sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 ) ) % sal_Int64( 60 ) ),
435cdf0e10cSrcweir             sal_uIntPtr( ( aTime / ( a100nPerSecond ) ) % sal_Int64( 60 ) ) );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     return DateTime( _aDate, _aTime );
438cdf0e10cSrcweir }
439