xref: /AOO41X/main/oox/source/helper/datetimehelper.cxx (revision 1f71f1d8c317442f96cd6d435bb275ff6e97eccb)
1*1f71f1d8SDamjan Jovanovic /**************************************************************
2*1f71f1d8SDamjan Jovanovic  *
3*1f71f1d8SDamjan Jovanovic  * Licensed to the Apache Software Foundation (ASF) under one
4*1f71f1d8SDamjan Jovanovic  * or more contributor license agreements.  See the NOTICE file
5*1f71f1d8SDamjan Jovanovic  * distributed with this work for additional information
6*1f71f1d8SDamjan Jovanovic  * regarding copyright ownership.  The ASF licenses this file
7*1f71f1d8SDamjan Jovanovic  * to you under the Apache License, Version 2.0 (the
8*1f71f1d8SDamjan Jovanovic  * "License"); you may not use this file except in compliance
9*1f71f1d8SDamjan Jovanovic  * with the License.  You may obtain a copy of the License at
10*1f71f1d8SDamjan Jovanovic  *
11*1f71f1d8SDamjan Jovanovic  *   http://www.apache.org/licenses/LICENSE-2.0
12*1f71f1d8SDamjan Jovanovic  *
13*1f71f1d8SDamjan Jovanovic  * Unless required by applicable law or agreed to in writing,
14*1f71f1d8SDamjan Jovanovic  * software distributed under the License is distributed on an
15*1f71f1d8SDamjan Jovanovic  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1f71f1d8SDamjan Jovanovic  * KIND, either express or implied.  See the License for the
17*1f71f1d8SDamjan Jovanovic  * specific language governing permissions and limitations
18*1f71f1d8SDamjan Jovanovic  * under the License.
19*1f71f1d8SDamjan Jovanovic  *
20*1f71f1d8SDamjan Jovanovic  *************************************************************/
21*1f71f1d8SDamjan Jovanovic 
22*1f71f1d8SDamjan Jovanovic #include "oox/helper/datetimehelper.hxx"
23*1f71f1d8SDamjan Jovanovic 
24*1f71f1d8SDamjan Jovanovic namespace oox {
25*1f71f1d8SDamjan Jovanovic 
26*1f71f1d8SDamjan Jovanovic // ============================================================================
27*1f71f1d8SDamjan Jovanovic 
28*1f71f1d8SDamjan Jovanovic using namespace ::com::sun::star::util;
29*1f71f1d8SDamjan Jovanovic 
30*1f71f1d8SDamjan Jovanovic using ::rtl::OUString;
31*1f71f1d8SDamjan Jovanovic 
32*1f71f1d8SDamjan Jovanovic // ============================================================================
33*1f71f1d8SDamjan Jovanovic 
34*1f71f1d8SDamjan Jovanovic bool parseISO8601DateTime( OUString &aValue, DateTime &dateTime )
35*1f71f1d8SDamjan Jovanovic {
36*1f71f1d8SDamjan Jovanovic     bool bValid = (aValue.getLength() >= 19) && (aValue[ 4 ] == '-') && (aValue[ 7 ] == '-') &&
37*1f71f1d8SDamjan Jovanovic         (aValue[ 10 ] == 'T') && (aValue[ 13 ] == ':') && (aValue[ 16 ] == ':');
38*1f71f1d8SDamjan Jovanovic     if( bValid )
39*1f71f1d8SDamjan Jovanovic     {
40*1f71f1d8SDamjan Jovanovic         dateTime.Year    = static_cast< sal_uInt16 >( aValue.copy( 0, 4 ).toInt32() );
41*1f71f1d8SDamjan Jovanovic         dateTime.Month   = static_cast< sal_uInt16 >( aValue.copy( 5, 2 ).toInt32() );
42*1f71f1d8SDamjan Jovanovic         dateTime.Day     = static_cast< sal_uInt16 >( aValue.copy( 8, 2 ).toInt32() );
43*1f71f1d8SDamjan Jovanovic         dateTime.Hours   = static_cast< sal_uInt16 >( aValue.copy( 11, 2 ).toInt32() );
44*1f71f1d8SDamjan Jovanovic         dateTime.Minutes = static_cast< sal_uInt16 >( aValue.copy( 14, 2 ).toInt32() );
45*1f71f1d8SDamjan Jovanovic         double seconds = aValue.copy( 17 ).toDouble();
46*1f71f1d8SDamjan Jovanovic         dateTime.Seconds = static_cast< sal_uInt16 >( floor( seconds ) );
47*1f71f1d8SDamjan Jovanovic         dateTime.HundredthSeconds = static_cast< sal_uInt16 >( round ( 100 * ( seconds - floor( seconds ) ) ) );
48*1f71f1d8SDamjan Jovanovic     }
49*1f71f1d8SDamjan Jovanovic     return bValid;
50*1f71f1d8SDamjan Jovanovic }
51*1f71f1d8SDamjan Jovanovic 
52*1f71f1d8SDamjan Jovanovic // ============================================================================
53*1f71f1d8SDamjan Jovanovic 
54*1f71f1d8SDamjan Jovanovic } // namespace oox
55