OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Read java.util.Date type value from a spreadsheet.

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
ynaras
Power User
Power User


Joined: 01 Nov 2004
Posts: 78
Location: Waltham, MA

PostPosted: Mon Mar 20, 2006 7:48 am    Post subject: Read java.util.Date type value from a spreadsheet. Reply with quote

Hi, I have searched through this forum and seen only one post on this topic: http://www.oooforum.org/forum/viewtopic.phtml?t=5608&highlight=java+read+date

I am however not convinced that the solution provided will work consistently when OOO comes out with new versions. Here is a question for experienced OOO hands like Danny Brewers and Pitonyaks out there:

What is the OOO recommended way to get calc Date type values into java.util.Date type value using OOO api?

Thanks,
Yogesh.
Back to top
View user's profile Send private message Visit poster's website
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Mar 20, 2006 8:08 am    Post subject: Reply with quote

How is the value stored in your Calc document? In other words, will you simply read a numeric value (double), or do you need to process a formatted string?

when you answer that question, then the answer should be obvious. My opinion is that the value as a numeric is easier, because then you know your starting point and you simply need to figure out how to convert it in Java. Every time that I learn the approved method in java, they seem to change it <grumble grumble>.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
ynaras
Power User
Power User


Joined: 01 Nov 2004
Posts: 78
Location: Waltham, MA

PostPosted: Mon Mar 20, 2006 8:20 am    Post subject: Reply with quote

Thanks for the fast response Andrew. I am storing all the date values as calc Date type. In calc, I display these dates using "DD-MONTH NAME-YYYY" format as that is the least ambiguous format.

It looks like you are suggesting reading the date type as a numeric type and then using "1/1/1899" as the starting point to convert all dates. Right? i.e. the algorithm specified in the posting: http://www.oooforum.org/forum/viewtopic.phtml?t=5608&highlight=java+read+date>, Right?

I am disappointed to learn that they keep changing the approved java method.

-Yogesh
Back to top
View user's profile Send private message Visit poster's website
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Mon Mar 20, 2006 12:37 pm    Post subject: Reply with quote

Quote:
I am disappointed to learn that they keep changing the approved java method.

I know why they do it, but these days, you need to use calendar objects and other things. I want the world to revolve around me and force everyone to do it my way. So, I want java to not only simply be setup for the Locale where I live and to fail for all other people. Better yet, I want it to read my mind and do what I want. Laughing

I think that this is all handled in the example that you see in your reference. If you do it any other way, then you need to parse the returned string. As it is, you need to guess at the time zone issues and such with what you get from Calc.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Mon Mar 20, 2006 12:54 pm    Post subject: Reply with quote

There is no data-type "date" nor "time" in a spreadsheet. Dates are doubles, starting at some day zero, incremented by one for each day. Times are the fractions of a double. Displaying dates just applies some nifty number format on a double.
Calc's day number zero is 1899-12-30 by default. The GUI lets you define two other days 1900-1-1 and 1904-1-1 (Tools>Options>Calc>Calculation), but you can set any day to be day zero.
Service com.sun.star.sheet.SpreadsheetDocumentSettings has a property com.sun.star.util.Date NullDate for each spreadsheet.
I don't program in java, but I believe there is a way to convert the NullDate of the document in question to double, add the double-value of the cell and get back the date value.
Back to top
View user's profile Send private message
ynaras
Power User
Power User


Joined: 01 Nov 2004
Posts: 78
Location: Waltham, MA

PostPosted: Mon Mar 20, 2006 2:26 pm    Post subject: Reply with quote

Hello Andrew and Villeroy, Thanks for the information.

Actually, I am fine with the way the calculation is done. I am however concerned about OOO changing something that will cause the code to break. On the bright side, these changes keeps us geeks employed, right? Very Happy

Villeroy, I will take a look at the com.sun.star.util.Date NullDate property. It looks like that is a good thing to know.

Thanks again for all the help,
Yogesh.
Back to top
View user's profile Send private message Visit poster's website
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Mar 21, 2006 6:49 am    Post subject: Reply with quote

if you will not be using current dates, then you need to know about the strange behavior related to the calendars (I document this in my book). Can't remember the details, but the calendar changed, and then there are some issues around zero.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group