| View previous topic :: View next topic |
| Author |
Message |
ynaras Power User


Joined: 01 Nov 2004 Posts: 78 Location: Waltham, MA
|
Posted: Mon Mar 20, 2006 7:48 am Post subject: Read java.util.Date type value from a spreadsheet. |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Mon Mar 20, 2006 8:08 am Post subject: |
|
|
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 |
|
 |
ynaras Power User


Joined: 01 Nov 2004 Posts: 78 Location: Waltham, MA
|
Posted: Mon Mar 20, 2006 8:20 am Post subject: |
|
|
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Mon Mar 20, 2006 12:37 pm Post subject: |
|
|
| 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.
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 |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Mon Mar 20, 2006 12:54 pm Post subject: |
|
|
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 |
|
 |
ynaras Power User


Joined: 01 Nov 2004 Posts: 78 Location: Waltham, MA
|
Posted: Mon Mar 20, 2006 2:26 pm Post subject: |
|
|
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?
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 |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Tue Mar 21, 2006 6:49 am Post subject: |
|
|
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 |
|
 |
|