Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/7456_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix Persian calendar leap year [[#7456](https://github.com/plotly/plotly.js/pull/7456)]
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@plotly/d3-sankey": "0.7.2",
"@plotly/d3-sankey-circular": "0.33.1",
"@plotly/mapbox-gl": "1.13.4",
"@plotly/regl": "^2.1.2",
"@turf/area": "^7.1.0",
"@turf/bbox": "^7.1.0",
"@turf/centroid": "^7.1.0",
Expand Down Expand Up @@ -105,7 +106,6 @@
"point-in-polygon": "^1.1.0",
"polybooljs": "^1.2.2",
"probe-image-size": "^7.2.3",
"@plotly/regl": "^2.1.2",
"regl-error2d": "^2.0.12",
"regl-line2d": "^3.1.3",
"regl-scatter2d": "^3.3.1",
Expand All @@ -117,10 +117,12 @@
"to-px": "1.0.1",
"topojson-client": "^3.1.0",
"webgl-context": "^2.2.0",
"world-calendars": "^1.0.3"
"world-calendars": "github:plotly/world-calendars#c82a7815f39d2c7de27e6fee59d7d4537d18304d"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@plotly/mathjax-v2": "npm:[email protected]",
"@plotly/mathjax-v3": "npm:mathjax@^3.2.2",
"amdefine": "^1.0.1",
"assert": "^2.1.0",
"browserify-transform-tools": "^1.7.0",
Expand Down Expand Up @@ -160,8 +162,6 @@
"karma-viewport": "1.0.2",
"lodash": "^4.17.21",
"madge": "^8.0.0",
"@plotly/mathjax-v2": "npm:[email protected]",
"@plotly/mathjax-v3": "npm:mathjax@^3.2.2",
"minify-stream": "^2.1.0",
"npm-link-check": "^5.0.1",
"open": "^8.4.2",
Expand Down
58 changes: 58 additions & 0 deletions test/jasmine/tests/lib_date_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,64 @@ describe('dates', function() {
expect(Lib.dateTime2ms(v, 'chinese')).toBeUndefined(v);
});
});

it('Persian calendar should convert right values', function() {
var leapYears = [
479, 483, 487, 491, 495, 499,
503, 508, 512, 516, 520, 524, 528, 532, 536, 541, 545, 549, 553, 557, 561, 565, 569, 574, 578, 582, 586, 590, 594, 598,
602, 607, 611, 615, 619, 623, 627, 631, 636, 640, 644, 648, 652, 656, 660, 664, 669, 673, 677, 681, 685, 689, 693, 697,
702, 706, 710, 714, 718, 722, 726, 730, 735, 739, 743, 747, 751, 755, 759, 764, 768, 772, 776, 780, 784, 788, 792, 797,
801, 805, 809, 813, 817, 821, 825, 830, 834, 838, 842, 846, 850, 854, 858, 863, 867, 871, 875, 879, 883, 887, 892, 896,
900, 904, 908, 912, 916, 920, 925, 929, 933, 937, 941, 945, 949, 953, 958, 962, 966, 970, 974, 978, 982, 986, 991, 995, 999,
1003, 1007, 1011, 1015, 1020, 1024, 1028, 1032, 1036, 1040, 1044, 1048, 1053, 1057, 1061, 1065, 1069, 1073, 1077, 1081, 1086, 1090, 1094, 1098,
1102, 1106, 1110, 1114, 1119, 1123, 1127, 1131, 1135, 1139, 1143, 1148, 1152, 1156, 1160, 1164, 1168, 1172, 1176, 1181, 1185, 1189, 1193, 1197,
1201, 1205, 1209, 1214, 1218, 1222, 1226, 1230, 1234, 1238, 1242, 1247, 1251, 1255, 1259, 1263, 1267, 1271, 1276, 1280, 1284, 1288, 1292, 1296,
1300, 1304, 1309, 1313, 1317, 1321, 1325, 1329, 1333, 1337, 1342, 1346, 1350, 1354, 1358, 1362, 1366, 1370, 1375, 1379, 1383, 1387, 1391, 1395, 1399,
1403, 1408, 1412, 1416, 1420, 1424, 1428, 1432, 1437, 1441, 1445, 1449, 1453, 1457, 1461, 1465, 1470, 1474, 1478, 1482, 1486, 1490, 1494, 1498,
1503, 1507, 1511, 1515, 1519, 1523
];

var dates = [];

for(var y = 475; y < 1525; y++) {
if(y === 0) continue;
for(var m = 1; m <= 12; m++) {
for(var d = 1; d <= (m < 7 ? 31 : 30); d++) {
if(d === 30 && m === 12 && leapYears.indexOf(y) === -1) continue;

dates.push([
(y < 1000 ? '0' : '') + y,
(m < 10 ? '0' : '') + m,
(d < 10 ? '0' : '') + d
].join('-'));
}
}
}

var unixIndex = dates.indexOf('1348-10-11');

var tests = [];
for(var i = 0; i < dates.length; i++) {
var date = dates[i];
var parts = date.split('-');
var d = +parts[2];

// only test days at the start/end of months
if(d < 3 || d > 28) {
var time = (i - unixIndex) * 86400000;

tests.push([date, time]);
}
}

tests.forEach(function(v) {
var calendar = 'persian';
var dateStr = v[0];
var ms = v[1];
expect(Lib.ms2DateTime(ms, 0, calendar)).toBe(dateStr);
expect(Lib.dateTime2ms(dateStr, calendar)).toBe(ms);
});
});
});

describe('cleanDate', function() {
Expand Down