Skip to content

Commit 891ba40

Browse files
committed
basic date separator support
1 parent 1a95148 commit 891ba40

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
21+
var days = [
22+
"Sunday",
23+
"Monday",
24+
"Tuesday",
25+
"Wednesday",
26+
"Thursday",
27+
"Friday",
28+
"Saturday"
29+
];
30+
31+
module.exports = React.createClass({
32+
displayName: 'DateSeparator',
33+
render: function() {
34+
var date = new Date(this.props.ts);
35+
var today = new Date();
36+
var yesterday = new Date();
37+
yesterday.setDate(today.getDate() - 1);
38+
var label;
39+
if (date.toDateString() === today.toDateString()) {
40+
label = "Today";
41+
}
42+
else if (date.toDateString() === yesterday.toDateString()) {
43+
label = "Yesterday";
44+
}
45+
else if (today.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) {
46+
label = days[date.getDay()];
47+
}
48+
else {
49+
label = date.toDateString();
50+
}
51+
52+
return (
53+
<h2>{ label }</h2>
54+
);
55+
}
56+
});

0 commit comments

Comments
 (0)