summaryrefslogtreecommitdiff
path: root/filter/source/msfilter/util.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'filter/source/msfilter/util.cxx')
-rw-r--r--filter/source/msfilter/util.cxx78
1 files changed, 78 insertions, 0 deletions
diff --git a/filter/source/msfilter/util.cxx b/filter/source/msfilter/util.cxx
index 03df8afb583a..adfe49222955 100644
--- a/filter/source/msfilter/util.cxx
+++ b/filter/source/msfilter/util.cxx
@@ -27,6 +27,7 @@
*/
#include <rtl/ustring.hxx>
+#include <rtl/strbuf.hxx>
#include <vcl/svapp.hxx>
#include <filter/msfilter/util.hxx>
@@ -62,6 +63,83 @@ sal_uInt32 BGRToRGB(sal_uInt32 nColor)
return nColor;
}
+DateTime DTTM2DateTime( long lDTTM )
+{
+ /*
+ mint short :6 0000003F minutes (0-59)
+ hr short :5 000007C0 hours (0-23)
+ dom short :5 0000F800 days of month (1-31)
+ mon short :4 000F0000 months (1-12)
+ yr short :9 1FF00000 years (1900-2411)-1900
+ wdy short :3 E0000000 weekday(Sunday=0
+ Monday=1
+ ( wdy can be ignored ) Tuesday=2
+ Wednesday=3
+ Thursday=4
+ Friday=5
+ Saturday=6)
+ */
+ DateTime aDateTime(Date( 0 ), Time( 0 ));
+ if( lDTTM )
+ {
+ sal_uInt16 lMin = (sal_uInt16)(lDTTM & 0x0000003F);
+ lDTTM >>= 6;
+ sal_uInt16 lHour= (sal_uInt16)(lDTTM & 0x0000001F);
+ lDTTM >>= 5;
+ sal_uInt16 lDay = (sal_uInt16)(lDTTM & 0x0000001F);
+ lDTTM >>= 5;
+ sal_uInt16 lMon = (sal_uInt16)(lDTTM & 0x0000000F);
+ lDTTM >>= 4;
+ sal_uInt16 lYear= (sal_uInt16)(lDTTM & 0x000001FF) + 1900;
+ aDateTime = DateTime(Date(lDay, lMon, lYear), Time(lHour, lMin));
+ }
+ return aDateTime;
+}
+
+/// Append the number as 2-digit when less than 10.
+static void lcl_AppendTwoDigits( rtl::OStringBuffer &rBuffer, sal_Int32 nNum )
+{
+ if ( nNum < 0 || nNum > 99 )
+ {
+ rBuffer.append( "00" );
+ return;
+ }
+
+ if ( nNum < 10 )
+ rBuffer.append( '0' );
+
+ rBuffer.append( nNum );
+}
+
+rtl::OString DateTimeToOString( const DateTime& rDateTime )
+{
+ DateTime aInUTC( rDateTime );
+// HACK: this is correct according to the spec, but MSOffice believes everybody lives
+// in UTC+0 when reading it back
+// aInUTC.ConvertToUTC();
+
+ rtl::OStringBuffer aBuffer( 25 );
+ aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
+ aBuffer.append( '-' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() );
+ aBuffer.append( '-' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetDay() );
+ aBuffer.append( 'T' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetHour() );
+ aBuffer.append( ':' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetMin() );
+ aBuffer.append( ':' );
+
+ lcl_AppendTwoDigits( aBuffer, aInUTC.GetSec() );
+ aBuffer.append( 'Z' ); // we are in UTC
+
+ return aBuffer.makeStringAndClear();
+}
+
}
}