Skip to content

Commit 61b14d6

Browse files
authoredFeb 12, 2023
Add deprecation warning to 2012-2022 pre-built files (#1036)
It's 2023 now, these files are producing incorrect results for the current year.
1 parent fc29369 commit 61b14d6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
 

‎Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function(grunt) {
1818
build : {
1919
'moment-timezone-with-data' : true,
2020
'moment-timezone-with-data-1970-2030' : [1970, 2030],
21-
'moment-timezone-with-data-2012-2022' : [2012, 2022],
21+
'moment-timezone-with-data-2012-2022' : [2012, 2022, 'warn'],
2222
'moment-timezone-with-data-10-year-range' : [currentYear - 5, currentYear + 5]
2323
},
2424

‎tasks/builds.js

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
var tz = require('../moment-timezone-utils').tz,
44
groupLeaders = require('./group-leaders.json');
55

6+
// A cut-down version of `deprecate()` from core moment.js
7+
function staleDataWarning() {
8+
if (moment.suppressDeprecationWarnings === false &&
9+
(typeof console !== 'undefined') && console.warn) {
10+
console.warn(
11+
'Deprecation warning: ' +
12+
'Moment Timezone has been loaded from a file containing data from 2012 to 2022 only. ' +
13+
'This file is out of date and may be removed in a future release. ' +
14+
'Dates and times for the current year might be incorrect.'
15+
);
16+
}
17+
}
18+
619
module.exports = function (grunt) {
720
grunt.registerMultiTask('build', 'Build minified versions with data included.', function () {
821
var dest = 'builds/' + this.target + '.js',
@@ -24,6 +37,11 @@ module.exports = function (grunt) {
2437
data = data.split('\n').join('\n\t');
2538
data = 'loadData(' + data + ');\n';
2639

40+
if (this.data && this.data[2] === 'warn') {
41+
data += '\n\t' + staleDataWarning.toString().split('\n').join('\n\t')
42+
+ '\n\tstaleDataWarning();'
43+
}
44+
2745
source = source.replace('// INJECT DATA', data);
2846

2947
grunt.file.write(dest, source);

0 commit comments

Comments
 (0)
Please sign in to comment.