Ah, The Joy of Dates!  If you go back further with Java you can find all sorts 
of peculiar things.

From: <webobjects-dev-bounces+chill=gevityinc....@lists.apple.com> on behalf of 
Theodore Petrosky <tedp...@yahoo.com>
Date: Monday, November 28, 2016 at 2:08 PM
To: Leigh Kivenko <lei...@portfolioaid.com>
Cc: WebObjects-Dev <webobjects-dev@lists.apple.com>
Subject: Re: excel dates

Why does excel behave so badly. well the original website I found said that 
excel calculated dates fro 01/01/1900 but that was incorrect. it is really 
01/00/1900, but there is more:

Actually, this number is one greater than the actual number of days.  This is 
because Excel behaves as if the date 1900-Feb-29 existed.  It did not.  The 
year 1900 was not a leap year (the year 2000 is a leap year).  In Excel, the 
day after 1900-Feb-28 is 1900-Feb-29.  In reality, the day after 1900-Feb-28  
was 1900-Mar-1 .  This is not a "bug".  Indeed, it is by design.  Excel works 
this way because it was truly a bug in Lotus 123.  When Excel was introduced, 
123 has nearly the entire market for spreadsheet software.  Microsoft decided 
to continue Lotus' bug, in order to fully compatible.  Users who switched from 
123 to Excel would not have to make any changes to their data.   As long as all 
your dates later than 1900-Mar-1, this should be of no concern.

My head hurts.

On Nov 28, 2016, at 1:17 PM, Leigh Kivenko 
<lei...@portfolioaid.com<mailto:lei...@portfolioaid.com>> wrote:

I think the century rule is overridden if it is also divisible by 400. So that 
explains 2000 and 1 of your days. The other day might just be an offset?

Leigh Kivenko | VP, Technology
PortfolioAid
t. 416-479-0523 | e. lei...@portfolioaid.com<mailto:lei...@portfolioaid.com>

This e-mail may be privileged and confidential. If you received this e-mail in 
error, please do not use, copy or distribute it, but advise me immediately (by 
return e-mail or otherwise), and delete the e-mail.

From: 
webobjects-dev-bounces+dev=portfolioaid....@lists.apple.com<mailto:webobjects-dev-bounces+dev=portfolioaid....@lists.apple.com>
 [mailto:webobjects-dev-bounces+dev=portfolioaid....@lists.apple.com] On Behalf 
Of Theodore Petrosky
Sent: Monday, November 28, 2016 1:08 PM
To: WebObjects-Dev 
<webobjects-dev@lists.apple.com<mailto:webobjects-dev@lists.apple.com>>
Subject: excel dates

So excel stores and expects to find date as an integer. The number of days 
since 01-01-1900.

I am trying to write out to excel and I have these dates. So is created a 
method that calculates the number of days from 01-01-1900. My problem is that I 
am two days off, so I adjusted the jan01 date two days.

Does anyone know why it is two days off? the only thing I can think of is that 
it is calculating the leap years incorrectly. every four years except century 
years, and there are two century years here (1900 and 2000),

       public int dateAsInt() {

              SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

              Date date = null;
              try {
                     date = format.parse ( "1899-12-30" );
              } catch (ParseException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
              }

              NSTimestamp jan011900 = new NSTimestamp(date);

              System.out.println(jan011900);

              long diff = eventDate().getTime() - jan011900.getTime(); // diff 
is in milliseconds
              long roundingOffset = ( diff >= 0 ) ? 12 : -12; // if diff is 
positive, offset up, if negative, offset down
              // next, convert diff to hours, offset by .5 days to round the 
end result, divide by 24 and truncate.
              long days = ( ( diff / ( 1000 * 60 * 60 ) ) + roundingOffset ) / 
24;

              return (int)days;
       }

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to