Exemple #1
0
        /**
         * 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));
        }
Exemple #3
0
        /// <summary> Constructs this object from the raw data
        ///
        /// </summary>
        /// <param name="num">the numerical representation of this
        /// </param>
        /// <param name="xfi">the java equivalent of the excel date format
        /// </param>
        /// <param name="fr"> the formatting records
        /// </param>
        /// <param name="nf"> flag indicating whether we are using the 1904 date system
        /// </param>
        /// <param name="si"> the sheet
        /// </param>
        public DateRecord(NumberCell num, int xfi, FormattingRecords fr, bool nf, SheetImpl si)
        {
            row               = num.Row;
            column            = num.Column;
            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.DoubleValue;

            // 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 && numValue < nonLeapDay)
            {
                numValue += 1;
            }

            if (System.Math.Abs(numValue) < 1)
            {
                if (format == null)
                {
                    format = timeFormat;
                }
                time = true;
            }
            else
            {
                if (format == null)
                {
                    format = dateFormat;
                }
                time = false;
            }

            // Get rid of any timezone adjustments - we are not interested
            // in automatic adjustments
            // [TODO-NExcel_Next]
//			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
//			long utcValue = (long) System.Math.Round(utcDays * msInADay);
            // convert it to 100 nanoseconds
            long utcValue = (long)System.Math.Round(utcDays * msInADay * 10000);

            // add the reference date (1/1/1970)
            DateTime refdate = new DateTime(1970, 1, 1);

            utcValue += refdate.Ticks;

            _Value = new DateTime(utcValue);
        }