Skip to content

Commit

Permalink
Add deprecation warning to 2012-2022 pre-built files (#1036)
Browse files Browse the repository at this point in the history
It's 2023 now, these files are producing incorrect results for
the current year.
  • Loading branch information
gilmoreorless committed Feb 12, 2023
1 parent fc29369 commit 61b14d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(grunt) {
build : {
'moment-timezone-with-data' : true,
'moment-timezone-with-data-1970-2030' : [1970, 2030],
'moment-timezone-with-data-2012-2022' : [2012, 2022],
'moment-timezone-with-data-2012-2022' : [2012, 2022, 'warn'],
'moment-timezone-with-data-10-year-range' : [currentYear - 5, currentYear + 5]
},

Expand Down
18 changes: 18 additions & 0 deletions tasks/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
var tz = require('../moment-timezone-utils').tz,
groupLeaders = require('./group-leaders.json');

// A cut-down version of `deprecate()` from core moment.js
function staleDataWarning() {
if (moment.suppressDeprecationWarnings === false &&
(typeof console !== 'undefined') && console.warn) {
console.warn(
'Deprecation warning: ' +
'Moment Timezone has been loaded from a file containing data from 2012 to 2022 only. ' +
'This file is out of date and may be removed in a future release. ' +
'Dates and times for the current year might be incorrect.'
);
}
}

module.exports = function (grunt) {
grunt.registerMultiTask('build', 'Build minified versions with data included.', function () {
var dest = 'builds/' + this.target + '.js',
Expand All @@ -24,6 +37,11 @@ module.exports = function (grunt) {
data = data.split('\n').join('\n\t');
data = 'loadData(' + data + ');\n';

if (this.data && this.data[2] === 'warn') {
data += '\n\t' + staleDataWarning.toString().split('\n').join('\n\t')
+ '\n\tstaleDataWarning();'
}

source = source.replace('// INJECT DATA', data);

grunt.file.write(dest, source);
Expand Down

0 comments on commit 61b14d6

Please sign in to comment.