/** * Constructs this object from the raw data * * @param num the numerical representation of this * @param xfi the java equivalent of the excel date format * @param fr the formatting records * @param nf flag indicating whether we are using the 1904 date system * @param si the sheet */ public DateRecord(NumberCell num, int xfi, FormattingRecords fr, bool nf, SheetImpl si) { row = num.getRow(); column = num.getColumn(); xfIndex = xfi; formattingRecords = fr; sheet = si; initialized = false; format = formattingRecords.getDateFormat(xfIndex); // This value represents the number of days since 01 Jan 1900 double numValue = num.getValue(); if (Math.Abs(numValue) < 1) { if (format == null) { format = timeFormat; } time = true; } else { if (format == null) { format = dateFormat; } time = false; } // Work round a bug in excel. Excel seems to think there is a date // called the 29th Feb, 1900 - but in actual fact this was not a leap year. // Therefore for values less than 61 in the 1900 date system, // add one to the numeric value if (!nf && !time && numValue < nonLeapDay) { numValue += 1; } // Get rid of any timezone adjustments - we are not interested // in automatic adjustments // TODO: CML -- don't know what to do here.... // format.setTimeZone(gmtZone); // Convert this to the number of days since 01 Jan 1970 int offsetDays = nf ? utcOffsetDays1904 : utcOffsetDays; double utcDays = numValue - offsetDays; // Convert this into utc by multiplying by the number of milliseconds // in a day. Use the round function prior to ms conversion due // to a rounding feature of Excel (contributed by Jurgen) long utcValue = (long)Math.Round(utcDays * secondsInADay) * msInASecond; date = new System.DateTime(ticksTo1970 + (utcValue * msTicks)); }
/** * Constructs this object from the raw data * * @param num the numerical representation of this * @param xfi the java equivalent of the excel date format * @param fr the formatting records * @param nf flag indicating whether we are using the 1904 date system * @param si the sheet */ public DateRecord(NumberCell num, int xfi,FormattingRecords fr, bool nf,SheetImpl si) { row = num.getRow(); column = num.getColumn(); xfIndex = xfi; formattingRecords = fr; sheet = si; initialized = false; format = formattingRecords.getDateFormat(xfIndex); // This value represents the number of days since 01 Jan 1900 double numValue = num.getValue(); if (Math.Abs(numValue) < 1) { if (format == null) format = timeFormat; time = true; } else { if (format == null) format = dateFormat; time = false; } // Work round a bug in excel. Excel seems to think there is a date // called the 29th Feb, 1900 - but in actual fact this was not a leap year. // Therefore for values less than 61 in the 1900 date system, // add one to the numeric value if (!nf && !time && numValue < nonLeapDay) { numValue += 1; } // Get rid of any timezone adjustments - we are not interested // in automatic adjustments // TODO: CML -- don't know what to do here.... // format.setTimeZone(gmtZone); // Convert this to the number of days since 01 Jan 1970 int offsetDays = nf ? utcOffsetDays1904 : utcOffsetDays; double utcDays = numValue - offsetDays; // Convert this into utc by multiplying by the number of milliseconds // in a day. Use the round function prior to ms conversion due // to a rounding feature of Excel (contributed by Jurgen) long utcValue = (long)Math.Round(utcDays * secondsInADay) * msInASecond; date = new System.DateTime(ticksTo1970 + (utcValue * msTicks)); }