diff options
author | Eike Rathke <erack@redhat.com> | 2014-08-19 19:05:40 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2014-08-19 21:54:44 +0200 |
commit | 11f145d90f6a6781be5ec3787f41cb1b76eb8c8c (patch) | |
tree | 1994f145ede48c04b432fd067433f7c3561fabf4 /sc | |
parent | f47baab6d35752b0babba768e299416ea5dd447d (diff) |
a date is a date, without time
And use DateTime instead of manually concatenating Date and Time.
Change-Id: I6f9fb988beea2a9a17c976d3b98860c4f9ed063b
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/view/viewfun6.cxx | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx index f6addba08c3d..483156b8d48f 100644 --- a/sc/source/ui/view/viewfun6.cxx +++ b/sc/source/ui/view/viewfun6.cxx @@ -244,15 +244,31 @@ void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr) ScDocument& rDoc = pDocSh->GetDocument(); ::svl::IUndoManager* pUndoMgr = pDocSh->GetUndoManager(); SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); - Date aActDate( Date::SYSTEM ); - double fDate = aActDate - *pFormatter->GetNullDate(); - Time aActTime( Time::SYSTEM ); - double fTime = aActTime.GetHour() / static_cast<double>(::Time::hourPerDay) + - aActTime.GetMin() / static_cast<double>(::Time::minutePerDay) + - aActTime.GetSec() / static_cast<double>(::Time::secondPerDay) + - aActTime.GetNanoSec() / static_cast<double>(::Time::nanoSecPerDay); + double fVal; + switch (nCellFmt) + { + case NUMBERFORMAT_DATE: + { + Date aActDate( Date::SYSTEM ); + fVal = aActDate - *pFormatter->GetNullDate(); + } + break; + default: + assert(!"unhandled current date/time"); + // fallthru + case NUMBERFORMAT_TIME: + case NUMBERFORMAT_DATETIME: // for now treat datetime and time identically + { + DateTime aActDateTime( DateTime::SYSTEM ); + // Converting the null date to DateTime forces the correct + // operator-() to be used, resulting in a fractional date&time + // instead of only date value. + fVal = aActDateTime - DateTime( *pFormatter->GetNullDate()); + } + break; + } pUndoMgr->EnterListAction(rUndoStr, rUndoStr); - pDocSh->GetDocFunc().SetValueCell(aCurPos, fDate+fTime, true); + pDocSh->GetDocFunc().SetValueCell(aCurPos, fVal, true); // Set the new cell format only when it differs from the current cell // format type. |