blob: 762d36d0b2d1933bcf707307df4e760034ffc842 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
import React from 'react';
import moment from 'moment';
import PropTypes from 'prop-types';
import './styles.css';
class GroupHeading extends React.Component {
getTitle() {
const startMoment = moment(this.props.start);
const currentMoment = moment();
const yesterdayMoment = moment().subtract(1, 'day');
// For "day" jumps show the day name
if (this.props.dateJump === 'day') {
if (startMoment.isSame(currentMoment, 'day')) {
return 'Today';
} else if (startMoment.isSame(yesterdayMoment, 'day')) {
return 'Yesterday';
}
return startMoment.format('dddd');
}
return startMoment.fromNow();
}
getSubtitle() {
const startMoment = moment(this.props.start);
const endMoment = moment(this.props.end);
if (startMoment.isSame(endMoment, 'day')) {
return startMoment.format('MMMM D, YYYY');
}
return startMoment.format('MMMM D, YYYY') + ' – ' + endMoment.format('MMMM D, YYYY');
}
render() {
return (
<div className="group-heading">
<h4>
<span className="text-capitalizes">{ this.getTitle() }</span>
<span className="small text-muted ml-2">
{ this.getSubtitle() }
</span>
</h4>
</div>
);
}
}
GroupHeading.propTypes = {
start: PropTypes.string,
end: PropTypes.string,
dateJump: PropTypes.oneOf(['week', 'month', 'year', 'day'])
};
export default GroupHeading;
|