@@ -15,26 +15,45 @@ limitations under the License.
1515*/
1616
1717import React from 'react' ;
18+ import { _t } from 'matrix-react-sdk/lib/languageHandler' ;
1819import DateUtils from 'matrix-react-sdk/lib/DateUtils' ;
19- import { Sticky } from 'react-sticky' ;
20+
21+ function getdaysArray ( ) {
22+ return [
23+ _t ( 'Sunday' ) ,
24+ _t ( 'Monday' ) ,
25+ _t ( 'Tuesday' ) ,
26+ _t ( 'Wednesday' ) ,
27+ _t ( 'Thursday' ) ,
28+ _t ( 'Friday' ) ,
29+ _t ( 'Saturday' ) ,
30+ ] ;
31+ }
2032
2133module . exports = React . createClass ( {
2234 displayName : 'DateSeparator' ,
2335 render : function ( ) {
24- const date = new Date ( this . props . ts ) ;
25- const label = DateUtils . formatDateSeparator ( date ) ;
36+ var date = new Date ( this . props . ts ) ;
37+ var today = new Date ( ) ;
38+ var yesterday = new Date ( ) ;
39+ var days = getdaysArray ( ) ;
40+ yesterday . setDate ( today . getDate ( ) - 1 ) ;
41+ var label ;
42+ if ( date . toDateString ( ) === today . toDateString ( ) ) {
43+ label = _t ( 'Today' ) ;
44+ }
45+ else if ( date . toDateString ( ) === yesterday . toDateString ( ) ) {
46+ label = _t ( 'Yesterday' ) ;
47+ }
48+ else if ( today . getTime ( ) - date . getTime ( ) < 6 * 24 * 60 * 60 * 1000 ) {
49+ label = days [ date . getDay ( ) ] ;
50+ }
51+ else {
52+ label = DateUtils . formatFullDate ( date , this . props . showTwelveHour ) ;
53+ }
54+
2655 return (
27- < Sticky relative = { true } disableCompensation = { true } >
28- { ( { style, isSticky, wasSticky, distanceFromTop} ) => {
29- return (
30- < div className = { "mx_DateSeparator_container mx_DateSeparator_container" + ( isSticky ? '_sticky' : '' ) }
31- style = { { top : isSticky ? - distanceFromTop + "px" : 0 } }
32- >
33- < h2 className = "mx_DateSeparator" > { label } </ h2 >
34- </ div >
35- ) ;
36- } }
37- </ Sticky >
56+ < h2 className = "mx_DateSeparator" > { label } </ h2 >
3857 ) ;
39- } ,
58+ }
4059} ) ;
0 commit comments