Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: fpdfsdk/src/javascript/JS_Value.cpp

Issue 1546443002: Merge to XFA: Fix JS seconds since epoch to date conversions. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: XFA changes Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « BUILD.gn ('k') | fpdfsdk/src/javascript/public_methods_embeddertest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "JS_Value.h" 7 #include "JS_Value.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 #include <cmath> 10 #include <cmath>
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0)); 642 return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0));
643 } 643 }
644 644
645 int _DayFromYear(int y) { 645 int _DayFromYear(int y) {
646 return (int)(365 * (y - 1970.0) + FXSYS_floor((y - 1969.0) / 4) - 646 return (int)(365 * (y - 1970.0) + FXSYS_floor((y - 1969.0) / 4) -
647 FXSYS_floor((y - 1901.0) / 100) + 647 FXSYS_floor((y - 1901.0) / 100) +
648 FXSYS_floor((y - 1601.0) / 400)); 648 FXSYS_floor((y - 1601.0) / 400));
649 } 649 }
650 650
651 double _TimeFromYear(int y) { 651 double _TimeFromYear(int y) {
652 return ((double)86400000) * _DayFromYear(y); 652 return 86400000.0 * _DayFromYear(y);
653 } 653 }
654 654
655 double _TimeFromYearMonth(int y, int m) { 655 double _TimeFromYearMonth(int y, int m) {
656 static int daysMonth[12] = { 656 static int daysMonth[12] = {
657 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; 657 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
658 static int leapDaysMonth[12] = { 658 static int leapDaysMonth[12] = {
659 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; 659 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
660 int* pMonth = daysMonth; 660 int* pMonth = daysMonth;
661 if (_isLeapYear(y)) 661 if (_isLeapYear(y))
662 pMonth = leapDaysMonth; 662 pMonth = leapDaysMonth;
663 return _TimeFromYear(y) + ((double)pMonth[m]) * 86400000; 663 return _TimeFromYear(y) + ((double)pMonth[m]) * 86400000;
664 } 664 }
665 665
666 int _Day(double t) { 666 int _Day(double t) {
667 return (int)FXSYS_floor(t / 86400000); 667 return (int)FXSYS_floor(t / 86400000);
668 } 668 }
669 669
670 int _YearFromTime(double t) { 670 int _YearFromTime(double t) {
671 // estimate the time. 671 // estimate the time.
672 int y = 1970 + (int)(t / (365.0 * 86400000)); 672 int y = 1970 + static_cast<int>(t / (365.2425 * 86400000));
673 if (_TimeFromYear(y) <= t) { 673 if (_TimeFromYear(y) <= t) {
674 while (_TimeFromYear(y + 1) <= t) 674 while (_TimeFromYear(y + 1) <= t)
675 y++; 675 y++;
676 } else 676 } else
677 while (_TimeFromYear(y - 1) > t) 677 while (_TimeFromYear(y) > t)
678 y--; 678 y--;
679 return y; 679 return y;
680 } 680 }
681 681
682 int _DayWithinYear(double t) { 682 int _DayWithinYear(double t) {
683 int year = _YearFromTime(t); 683 int year = _YearFromTime(t);
684 int day = _Day(t); 684 int day = _Day(t);
685 return day - _DayFromYear(year); 685 return day - _DayFromYear(year);
686 } 686 }
687 687
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 return day * 86400000 + time; 862 return day * 86400000 + time;
863 } 863 }
864 864
865 bool JS_PortIsNan(double d) { 865 bool JS_PortIsNan(double d) {
866 return d != d; 866 return d != d;
867 } 867 }
868 868
869 double JS_LocalTime(double d) { 869 double JS_LocalTime(double d) {
870 return JS_GetDateTime() + _getDaylightSavingTA(d); 870 return JS_GetDateTime() + _getDaylightSavingTA(d);
871 } 871 }
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | fpdfsdk/src/javascript/public_methods_embeddertest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698