From 2a53a72fbffe285fb50193f853bab60db61ccf54 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 10 Apr 2013 15:03:12 -0400 Subject: Properly implement date / time value import from orcus. Change-Id: Icaf310182dcdd2a5d06c2d4bcbb98e3850fb2d80 --- sc/source/filter/inc/orcusinterface.hxx | 3 ++- sc/source/filter/orcus/interface.cxx | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'sc') diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx index 69e123b914c4..4cb03fa38a30 100644 --- a/sc/source/filter/inc/orcusinterface.hxx +++ b/sc/source/filter/inc/orcusinterface.hxx @@ -62,7 +62,8 @@ public: virtual void set_string(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, size_t sindex); virtual void set_value(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, double value); virtual void set_bool(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, bool value); - virtual void set_date(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, const char* p, size_t n); + virtual void set_date_time( + orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, int year, int month, int day, int hour, int minute, double second); virtual void set_format(orcus::spreadsheet::row_t row, orcus::spreadsheet::col_t col, size_t xf_index); diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index 5c00e56f373c..06d03ba23bdb 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -15,7 +15,10 @@ #include "tokenarray.hxx" #include "stringutil.hxx" -#include +#include "formula/token.hxx" +#include "tools/datetime.hxx" + +#define D_TIMEFACTOR 86400.0 using orcus::spreadsheet::row_t; using orcus::spreadsheet::col_t; @@ -148,9 +151,27 @@ void ScOrcusSheet::set_bool(row_t row, col_t col, bool value) mrDoc.SetValue(col, row, mnTab, value ? 1.0 : 0.0); } -void ScOrcusSheet::set_date(row_t row, col_t col, const char* p, size_t n) +void ScOrcusSheet::set_date_time( + row_t row, col_t col, int year, int month, int day, int hour, int minute, double second) { - set_auto(row, col, p, n); + SvNumberFormatter* pFormatter = mrDoc.GetFormatTable(); + + Date aDate(day, month, year); + sal_uIntPtr nSec = floor(second); + sal_uIntPtr nSec100 = (second - nSec) * 100; + Time aTime(hour, minute, nSec, nSec100); + Date aNullDate(*pFormatter->GetNullDate()); + long nDateDiff = aDate - aNullDate; + + double fTime = + static_cast(aTime.Get100Sec()) / 100.0 + + aTime.GetSec() + + aTime.GetMin() * 60.0 + + aTime.GetHour() * 3600.0; + + fTime /= D_TIMEFACTOR; + + mrDoc.SetValue(col, row, mnTab, nDateDiff + fTime); } void ScOrcusSheet::set_format(row_t /*row*/, col_t /*col*/, size_t /*xf_index*/) -- cgit