Skip to content

Commit e4a9ca9

Browse files
authored
Use @wojtekmaj/date-utils package (#61)
1 parent 17889c6 commit e4a9ca9

File tree

13 files changed

+24
-130
lines changed

13 files changed

+24
-130
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"license": "MIT",
4242
"dependencies": {
43+
"@wojtekmaj/date-utils": "^1.0.0",
4344
"get-user-locale": "^1.2.0",
4445
"make-event-props": "^1.1.0",
4546
"merge-class-names": "^1.1.1",

src/TimeInput.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
33
import { polyfill } from 'react-lifecycles-compat';
4+
import {
5+
getHours,
6+
getMinutes,
7+
getSeconds,
8+
getHoursMinutes,
9+
getHoursMinutesSeconds,
10+
} from '@wojtekmaj/date-utils';
411

512
import Divider from './Divider';
613
import Hour12Input from './TimeInput/Hour12Input';
@@ -11,15 +18,7 @@ import NativeInput from './TimeInput/NativeInput';
1118
import AmPm from './TimeInput/AmPm';
1219

1320
import { getFormatter } from './shared/dateFormatter';
14-
import {
15-
getHours,
16-
getMinutes,
17-
getSeconds,
18-
getHoursMinutes,
19-
getHoursMinutesSeconds,
20-
convert12to24,
21-
convert24to12,
22-
} from './shared/dates';
21+
import { convert12to24, convert24to12 } from './shared/dates';
2322
import { isTime } from './shared/propTypes';
2423
import { getAmPmLabels } from './shared/utils';
2524

src/TimeInput/AmPm.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import mergeClassNames from 'merge-class-names';
4+
import { getHours } from '@wojtekmaj/date-utils';
45

5-
import {
6-
getHours,
7-
convert24to12,
8-
} from '../shared/dates';
6+
import { convert24to12 } from '../shared/dates';
97
import { isTime } from '../shared/propTypes';
108
import { getAmPmLabels } from '../shared/utils';
119

src/TimeInput/Hour12Input.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { getHours } from '@wojtekmaj/date-utils';
34

45
import Input from './Input';
56

67
import {
7-
getHours,
88
convert24to12,
99
} from '../shared/dates';
1010
import { isTime } from '../shared/propTypes';

src/TimeInput/Hour24Input.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { getHours } from '@wojtekmaj/date-utils';
34

45
import Input from './Input';
56

6-
import { getHours } from '../shared/dates';
77
import { isTime } from '../shared/propTypes';
88
import { min, max } from '../shared/utils';
99

src/TimeInput/MinuteInput.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { getHours, getMinutes } from '@wojtekmaj/date-utils';
34

45
import Input from './Input';
56

6-
import { getHours, getMinutes } from '../shared/dates';
77
import { isTime } from '../shared/propTypes';
88
import { min, max } from '../shared/utils';
99

src/TimeInput/NativeInput.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
43
import {
54
getHours,
65
getHoursMinutes,
76
getHoursMinutesSeconds,
8-
} from '../shared/dates';
7+
} from '@wojtekmaj/date-utils';
8+
99
import { isTime, isValueType } from '../shared/propTypes';
1010

1111
export default function NativeInput({

src/TimeInput/SecondInput.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import { getHours, getMinutes, getSeconds } from '@wojtekmaj/date-utils';
34

45
import Input from './Input';
56

6-
import {
7-
getHours,
8-
getMinutes,
9-
getSeconds,
10-
} from '../shared/dates';
117
import { isTime } from '../shared/propTypes';
128
import { min, max } from '../shared/utils';
139

src/shared/dates.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
1-
import {
2-
getHours,
3-
getMinutes,
4-
getSeconds,
5-
} from 'react-clock/dist/shared/dates';
6-
7-
export {
8-
getHours,
9-
getMinutes,
10-
getSeconds,
11-
};
12-
13-
export function getHoursMinutes(date) {
14-
if (!date) {
15-
return date;
16-
}
17-
18-
const hours = `0${getHours(date)}`.slice(-2);
19-
const minutes = `0${getMinutes(date)}`.slice(-2);
20-
21-
return `${hours}:${minutes}`;
22-
}
23-
24-
export function getHoursMinutesSeconds(date) {
25-
if (!date) {
26-
return date;
27-
}
28-
29-
const hours = `0${getHours(date)}`.slice(-2);
30-
const minutes = `0${getMinutes(date)}`.slice(-2);
31-
const seconds = `0${getSeconds(date)}`.slice(-2);
32-
33-
return `${hours}:${minutes}:${seconds}`;
34-
}
35-
361
export function convert12to24(hour12, amPm) {
372
let hour24 = parseInt(hour12, 10);
383

src/shared/dates.spec.js

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,8 @@
11
import {
2-
getHoursMinutes,
3-
getHoursMinutesSeconds,
42
convert12to24,
53
convert24to12,
64
} from './dates';
75

8-
describe('getHoursMinutes', () => {
9-
it('returns proper hour and minute for a given date', () => {
10-
const date = new Date(2017, 0, 1, 16, 4);
11-
12-
const hoursMinutes = getHoursMinutes(date);
13-
14-
expect(hoursMinutes).toBe('16:04');
15-
});
16-
17-
it('returns proper hour and minute for a given string of hour and minute', () => {
18-
const date = '16:04';
19-
20-
const hoursMinutes = getHoursMinutes(date);
21-
22-
expect(hoursMinutes).toBe('16:04');
23-
});
24-
25-
it('returns proper hour and minute for a given string of hour, minute and second', () => {
26-
const date = '16:04:08';
27-
28-
const hoursMinutes = getHoursMinutes(date);
29-
30-
expect(hoursMinutes).toBe('16:04');
31-
});
32-
33-
it('throws an error when given nonsense data', () => {
34-
const text = 'wololo';
35-
const flag = true;
36-
37-
expect(() => getHoursMinutes(text)).toThrow();
38-
expect(() => getHoursMinutes(flag)).toThrow();
39-
});
40-
});
41-
42-
describe('getHoursMinutesSeconds', () => {
43-
it('returns proper hour, minute and second for a given date', () => {
44-
const date = new Date(2017, 0, 1, 16, 4, 41);
45-
46-
const hoursMinutesSeconds = getHoursMinutesSeconds(date);
47-
48-
expect(hoursMinutesSeconds).toBe('16:04:41');
49-
});
50-
51-
it('returns proper hour, minute and second for a given string of hour and minute', () => {
52-
const date = '16:04';
53-
54-
const hoursMinutesSeconds = getHoursMinutesSeconds(date);
55-
56-
expect(hoursMinutesSeconds).toBe('16:04:00');
57-
});
58-
59-
it('returns proper hour, minute and second for a given string of hour, minute and second', () => {
60-
const date = '16:04:08';
61-
62-
const hoursMinutesSeconds = getHoursMinutesSeconds(date);
63-
64-
expect(hoursMinutesSeconds).toBe('16:04:08');
65-
});
66-
67-
it('throws an error when given nonsense data', () => {
68-
const text = 'wololo';
69-
const flag = true;
70-
71-
expect(() => getHoursMinutesSeconds(text)).toThrow();
72-
expect(() => getHoursMinutesSeconds(flag)).toThrow();
73-
});
74-
});
75-
766
describe('convert12to24', () => {
777
it.each`
788
hour12 | amPm | hour24

0 commit comments

Comments
 (0)