Skip to content

Commit 1e03f84

Browse files
committed
Turns moment timezone peer dependency in a runtime error when missing using displayTimezone
1 parent b8af389 commit 1e03f84

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

DateTime.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ var Datetime = createClass({
4646
},
4747

4848
getInitialState: function() {
49+
this.checkTZ( this.props );
50+
4951
var state = this.getStateFromProps( this.props );
5052

5153
if ( state.open === undefined )
@@ -207,13 +209,9 @@ var Datetime = createClass({
207209
if ( nextProps.viewDate !== this.props.viewDate ) {
208210
updatedState.viewDate = moment(nextProps.viewDate);
209211
}
210-
//we should only show a valid date if we are provided a isValidDate function. Removed in 2.10.3
211-
/*if (this.props.isValidDate) {
212-
updatedState.viewDate = updatedState.viewDate || this.state.viewDate;
213-
while (!this.props.isValidDate(updatedState.viewDate)) {
214-
updatedState.viewDate = updatedState.viewDate.add(1, 'day');
215-
}
216-
}*/
212+
213+
this.checkTZ( nextProps );
214+
217215
this.setState( updatedState );
218216
},
219217

@@ -408,6 +406,15 @@ var Datetime = createClass({
408406
return m;
409407
},
410408

409+
checkTZ: function( props ) {
410+
var con = console;
411+
412+
if ( props.displayTimeZone && !this.tzWarning && !moment.tz ) {
413+
this.tzWarning = true;
414+
con && con.error('react-datetime: displayTimeZone prop with value "' + props.displayTimeZone + '" is used but moment.js timezone is not loaded.');
415+
}
416+
},
417+
411418
componentProps: {
412419
fromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear', 'timeConstraints'],
413420
fromState: ['viewDate', 'selectedDate', 'updateOn'],
@@ -473,7 +480,7 @@ var Datetime = createClass({
473480
onKeyDown: this.overrideEvent( 'onKeyDown', this.onInputKey ),
474481
}
475482
);
476-
483+
477484
if ( this.props.renderInput ) {
478485
children = [ React.createElement('div', { key: 'i' }, this.props.renderInput( finalInputProps, this.openCalendar, this.closeCalendar )) ];
479486
} else {

dist/react-datetime.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
react-datetime v2.16.1
2+
react-datetime v2.16.2
33
https://github.com/YouCanBookMe/react-datetime
44
MIT: https://github.com/YouCanBookMe/react-datetime/raw/master/LICENSE
55
*/
@@ -115,6 +115,8 @@ return /******/ (function(modules) { // webpackBootstrap
115115
state.currentView = this.props.dateFormat ?
116116
(this.props.viewMode || state.updateOn || viewModes.DAYS) : viewModes.TIME;
117117

118+
this.checkTZ( this.props );
119+
118120
return state;
119121
},
120122

@@ -268,13 +270,9 @@ return /******/ (function(modules) { // webpackBootstrap
268270
if ( nextProps.viewDate !== this.props.viewDate ) {
269271
updatedState.viewDate = moment(nextProps.viewDate);
270272
}
271-
//we should only show a valid date if we are provided a isValidDate function. Removed in 2.10.3
272-
/*if (this.props.isValidDate) {
273-
updatedState.viewDate = updatedState.viewDate || this.state.viewDate;
274-
while (!this.props.isValidDate(updatedState.viewDate)) {
275-
updatedState.viewDate = updatedState.viewDate.add(1, 'day');
276-
}
277-
}*/
273+
274+
this.checkTZ( nextProps );
275+
278276
this.setState( updatedState );
279277
},
280278

@@ -469,6 +467,15 @@ return /******/ (function(modules) { // webpackBootstrap
469467
return m;
470468
},
471469

470+
checkTZ: function( props ) {
471+
var con = console;
472+
473+
if ( props.displayTimeZone && !this.tzWarning && !moment.tz ) {
474+
this.tzWarning = true;
475+
con && con.error('react-datetime: displayTimeZone prop with value "' + props.displayTimeZone + '" is used but moment.js timezone is not loaded.');
476+
}
477+
},
478+
472479
componentProps: {
473480
fromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear', 'timeConstraints'],
474481
fromState: ['viewDate', 'selectedDate', 'updateOn'],
@@ -534,7 +541,7 @@ return /******/ (function(modules) { // webpackBootstrap
534541
onKeyDown: this.overrideEvent( 'onKeyDown', this.onInputKey ),
535542
}
536543
);
537-
544+
538545
if ( this.props.renderInput ) {
539546
children = [ React.createElement('div', { key: 'i' }, this.props.renderInput( finalInputProps, this.openCalendar, this.closeCalendar )) ];
540547
} else {

dist/react-datetime.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-datetime.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-datetime",
3-
"version": "2.16.1",
3+
"version": "2.16.2",
44
"description": "A lightweight but complete datetime picker React.js component",
55
"homepage": "https://github.com/YouCanBookMe/react-datetime",
66
"repository": {
@@ -41,7 +41,6 @@
4141
"license": "MIT",
4242
"peerDependencies": {
4343
"moment": ">=2.16.0",
44-
"moment-timezone": "^0.5.13",
4544
"react": ">=0.13",
4645
"react-dom": ">=0.13"
4746
},

0 commit comments

Comments
 (0)