diff --git a/CHANGELOG.md b/CHANGELOG.md
index 36d411b..9dfd731 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## v4.0.9
### Fixed
- Calendar component would choose current time first time you are selecting a date. Now defaults to 12:00 AM local
+- fix off by one issue with date picker
- unit tests were not running
- removed unused dependencies
- updated max-width on buttons to be 100% of the parent width
diff --git a/lib/components/DateTime/DatePicker.md b/lib/components/DateTime/DatePicker.md
index 629a6b1..dc9afc7 100644
--- a/lib/components/DateTime/DatePicker.md
+++ b/lib/components/DateTime/DatePicker.md
@@ -36,6 +36,8 @@ const initialState = {value: ''};
```
+### utc time
+
```jsx
const initialValue = 'Sep 20, 2010 07:00:00 GMT';
const initialState = {value: ''};
@@ -51,6 +53,22 @@ const initialState = {value: ''};
```
+### local time
+
+```jsx
+const initialValue = 'Sep 20, 2010 07:00:00 GMT';
+const initialState = {value: ''};
+
+
+
Current Value: {state.value}
+
setState({value: newValue}) }
+ initialValue={initialValue}
+ />
+
+```
+
```jsx
const initialValue = null;
const initialState = {value: ''};
diff --git a/lib/components/DateTime/DatePicker.spec.tsx b/lib/components/DateTime/DatePicker.spec.tsx
index 1edef2e..e0bb563 100644
--- a/lib/components/DateTime/DatePicker.spec.tsx
+++ b/lib/components/DateTime/DatePicker.spec.tsx
@@ -6,6 +6,13 @@ import { DateFormat} from '../../Common';
import { DatePicker} from './DatePicker';
import { describe, it } from 'mocha';
+const adjustForTimezone = (dateStr) => {
+ let date = new Date(dateStr);
+ let timeOffsetInMS = date.getTimezoneOffset() * 60000;
+ date.setTime(date.getTime() - timeOffsetInMS);
+ return date.toISOString();
+};
+
describe('DatePicker', () => {
let clock;
beforeEach(() => {
@@ -16,23 +23,35 @@ describe('DatePicker', () => {
clock.restore();
});
- it('should accept a valid date string for initial value', () => {
+ it('should set the text box value when initial value is a valid date', () => {
const onChange = sinon.spy();
const wrapper = shallow();
- expect(wrapper.instance().state.value).to.equal('28/09/2017');
+ expect(wrapper.instance().state.value).to.equal('06/12/2018');
+ });
+
+ it('should pass through initial value to text box when initial value is not a valid date', () => {
+ const onChange = sinon.spy();
+ const wrapper = shallow();
+
+ expect(wrapper.instance().state.value).to.equal('2018-28-28T00:00:00.000');
});
it('should pass invalid through change callback when date value is garbage text', () => {
const onChange = sinon.spy();
const wrapper = shallow();
@@ -47,7 +66,7 @@ describe('DatePicker', () => {
const onChange = sinon.spy();
const wrapper = shallow();
@@ -62,7 +81,7 @@ describe('DatePicker', () => {
const onChange = sinon.spy();
const wrapper = shallow();
@@ -77,7 +96,7 @@ describe('DatePicker', () => {
const onChange = sinon.spy();
const wrapper = shallow();
@@ -113,21 +132,7 @@ describe('DatePicker', () => {
const input = wrapper.find('.date-picker-input');
input.simulate('change', {target: {value: '28/09/2018'}});
expect(onChange.called).to.equal(true);
- expect(onChange.firstCall.args[0]).to.equal('2018-09-28T23:00:00.000Z');
- });
-
- it('should accept mm/dd/yyyy format as a valid input', () => {
- const onChange = sinon.spy();
- const wrapper = shallow();
-
- const input = wrapper.find('.date-picker-input');
- input.simulate('change', {target: {value: '09/28/2018'}});
- expect(onChange.called).to.equal(true);
- expect(onChange.firstCall.args[0]).to.equal('2018-09-28T23:00:00.000Z');
+ expect(adjustForTimezone(onChange.firstCall.args[0])).to.equal('2018-09-28T00:00:00.000Z');
});
it('should accept iso format as a valid input', () => {
@@ -141,10 +146,10 @@ describe('DatePicker', () => {
const input = wrapper.find('.date-picker-input');
input.simulate('change', {target: {value: '2018/09/28'}});
expect(onChange.called).to.equal(true);
- expect(onChange.firstCall.args[0]).to.equal('2018-09-28T23:00:00.000Z');
+ expect(adjustForTimezone(onChange.firstCall.args[0])).to.equal('2018-09-28T00:00:00.000Z');
});
- it('should set time to epoch when initial value is empty', () => {
+ it('should set time to midnight gmt + localoffest when initial value is empty', () => {
const onChange = sinon.spy();
const wrapper = shallow( {
/>);
const input = wrapper.find('.date-picker-input');
- input.simulate('change', {target: {value: '2018/09/28 10:12:13'}});
+ input.simulate('change', {target: {value: '2018/09/28'}});
expect(onChange.called).to.equal(true);
- expect(onChange.firstCall.args[0]).to.equal('2018-09-28T23:00:00.000Z');
+ expect(adjustForTimezone(onChange.firstCall.args[0])).to.equal('2018-09-28T00:00:00.000Z');
});
- it('should set time to epoch when initial value is not empty', () => {
+ it('should set time to midnight gmt + localoffest when initial value is not empty', () => {
const onChange = sinon.spy();
const wrapper = shallow();
const input = wrapper.find('.date-picker-input');
- input.simulate('change', {target: {value: '2018/09/29 10:12:13'}});
+ input.simulate('change', {target: {value: '2018/09/29'}});
expect(onChange.called).to.equal(true);
- expect(onChange.firstCall.args[0]).to.equal('2018-09-29T23:00:00.000Z');
+ expect(adjustForTimezone(onChange.firstCall.args[0])).to.equal('2018-09-29T00:00:00.000Z');
});
-});
+
+ it('should set time to midnight when initial value is not empty and localTimezone is false', () => {
+ const onChange = sinon.spy();
+ const wrapper = shallow();
+
+ const input = wrapper.find('.date-picker-input');
+ input.simulate('change', {target: {value: '2018/09/29'}});
+ expect(onChange.called).to.equal(true);
+ expect(onChange.firstCall.args[0]).to.equal('2018-09-29T00:00:00.000Z');
+ });
+});
\ No newline at end of file
diff --git a/lib/components/DateTime/DatePicker.tsx b/lib/components/DateTime/DatePicker.tsx
index 1b5f3b9..301b033 100644
--- a/lib/components/DateTime/DatePicker.tsx
+++ b/lib/components/DateTime/DatePicker.tsx
@@ -174,6 +174,7 @@ export class DatePicker extends React.Component
diff --git a/lib/components/DateTime/DateTimeField.md b/lib/components/DateTime/DateTimeField.md
index db4d102..c172754 100644
--- a/lib/components/DateTime/DateTimeField.md
+++ b/lib/components/DateTime/DateTimeField.md
@@ -28,7 +28,7 @@ ______________________________________________________________________________
const initialState = {value: 'Sep 20, 2010 05:00:00 GMT'};
-
Current Value: {state.value}
+
Current Value: {new Date(state.value).toString()}
- Current Value: {state.value}
+ Current Value: {new Date(state.value).toString()}
- Current Value: {state.value}
+ Current Value: {new Date(state.value).toString()}
- Current Value: {state.value}
+ Current Value: {new Date(state.value).toString()}
{
/**
* callback for clicking calendar icon
*/
- onExpand?: (expanded: boolean) => void
+ onExpand?: (expanded: boolean) => void;
attr?: DateTimeFieldAttributes & FormFieldAttributes;
}
diff --git a/lib/components/DateTime/helpers.ts b/lib/components/DateTime/helpers.ts
index 043b512..a54f4a8 100644
--- a/lib/components/DateTime/helpers.ts
+++ b/lib/components/DateTime/helpers.ts
@@ -51,4 +51,4 @@ export const getLocalMonths = (locale) => {
}
return monthNames;
-};
+};
\ No newline at end of file
diff --git a/mocha.opts b/mocha.opts
index edce3ad..637a45e 100644
--- a/mocha.opts
+++ b/mocha.opts
@@ -2,5 +2,6 @@
--require source-map-support/register
--require ignore-styles
--recursive
+--exclude ./src/**/*.js
--file ./test/browser.js
./lib/**/*.spec.tsx
\ No newline at end of file
diff --git a/package.json b/package.json
index 68c1409..66dcfb2 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,8 @@
"tslint": "tslint './lib/**/*.ts{,x}'",
"sasslint": "sass-lint -c .sass-lint.yml 'lib/**/*.scss' -v -q",
"docs": "styleguidist server",
- "docs:build": "styleguidist build"
+ "docs:build": "styleguidist build",
+ "prepublish": "npm run tslint && npm run test && npm run build"
},
"repository": {
"type": "git",