|
- var MAX_DATE = 2958465
- var MAX_DATE_1904 = 2957003
-
-
- var HALF_SECOND = (1.0 / 172800.0)
-
-
- var HALF_MILLISECOND = (1.0 / 2000.0)
-
-
- var SERIAL_BASE_NUM = 693959
-
-
- var SERIAL_BASE_NUM_1904 = 695421
-
-
- var YEAR1900_ISLEAP = 0
-
-
- var _afxMonthDays =
- [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
- var b1904 = false;
- var bDisable1900Year = false;
-
- function toTime(dtSrc, b1904) {
- var tmDest = {};
- var nDays = 0;
- var nDaysAbsolute = 0;
- var nSecsInDay = 0;
- var nMinutesInDay = 0;
-
- var n400Years = 0;
- var n400Century = 0;
- var n4Years = 0;
- var n4Day = 0;
-
- var n4Yr = 0;
- var bLeap4 = true;
- var bIs1900Year = false;
-
- var dblDate = dtSrc;
-
-
- if (0 == 0)
- dblDate += ((dtSrc > 0.0) ? HALF_SECOND : -HALF_SECOND);
-
-
- nDays = Math.floor(dblDate);
-
- nDaysAbsolute = Math.floor(dblDate) + (b1904 ? SERIAL_BASE_NUM_1904 : SERIAL_BASE_NUM);
-
- dblDate = Math.abs(dblDate);
- var dblSecsInDay = (dblDate - Math.floor(dblDate)) * 86400.0;
-
- nSecsInDay = Math.floor(dblSecsInDay);
-
-
-
-
- tmDest.tm_wday = Math.floor((nDaysAbsolute - 1) % 7);
-
- if (!bDisable1900Year && !b1904 &&
- nDaysAbsolute >= SERIAL_BASE_NUM &&
- nDaysAbsolute < SERIAL_BASE_NUM + 367) {
- bIs1900Year = true;
- n4Day = nDaysAbsolute - SERIAL_BASE_NUM;
- bLeap4 = true;
- n400Years = 4;
- n400Century = 3;
- n4Yr = 0;
- }
- else {
-
- n400Years = Math.floor(nDaysAbsolute / 146097);
-
-
- nDaysAbsolute %= 146097;
-
-
- n400Century = Math.floor((nDaysAbsolute - 1) / 36524);
-
-
- if (n400Century != 0) {
-
- nDaysAbsolute = (nDaysAbsolute - 1) % 36524;
-
-
- n4Years = Math.floor((nDaysAbsolute + 1) / 1461);
-
- if (n4Years != 0)
- n4Day = Math.floor((nDaysAbsolute + 1) % 1461);
- else {
- bLeap4 = false;
- n4Day = Math.floornDaysAbsolute;
- }
- }
- else {
-
- n4Years = Math.floor(nDaysAbsolute / 1461);
- n4Day = Math.floor(nDaysAbsolute % 1461);
- }
-
- if (bLeap4) {
-
- n4Yr = (n4Day - 1) / 365;
-
- if (n4Yr != 0)
- n4Day = (n4Day - 1) % 365;
- }
- else {
- n4Yr = n4Day / 365;
- n4Day %= 365;
- }
- }
-
-
- tmDest.tm_yday = Math.floor(n4Day) + 1;
- tmDest.tm_year = Math.floor(n400Years * 400 + n400Century * 100 + n4Years * 4 + n4Yr);
-
-
- if (n4Yr == 0 && bLeap4) {
-
- if ((!bIs1900Year && n4Day == 59) ||
- (bIs1900Year && n4Day == 60)) {
-
- tmDest.tm_mon = 2;
- tmDest.tm_mday = 29;
- }
- else {
-
- if (n4Day >= 60)
- --n4Day;
- }
- } else {
-
-
- if (!bIs1900Year)
- ++n4Day;
-
-
- for (tmDest.tm_mon = (n4Day >> 5) + 1;
- n4Day > _afxMonthDays[tmDest.tm_mon]; tmDest.tm_mon++);
-
- tmDest.tm_mday = Math.floor(n4Day - _afxMonthDays[tmDest.tm_mon - 1]);
- }
-
- if (nSecsInDay == 0)
- tmDest.tm_hour = tmDest.tm_min = tmDest.tm_sec = 0;
- else {
- tmDest.tm_sec = Math.floor(nSecsInDay % 60);
- nMinutesInDay = nSecsInDay / 60;
- tmDest.tm_min = Math.floor(nMinutesInDay % 60);
- tmDest.tm_hour = Math.floor(nMinutesInDay / 60);
- }
-
- return new Date(tmDest.tm_year, tmDest.tm_mon + 1, tmDest.tm_mday, tmDest.tm_mday, tmDest.tm_min, tmDest.tm_sec);
- }
|