Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deprecation warning to 2012-2022 pre-built files #1036

Merged
merged 1 commit into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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