feat: finish weather, add week number back, improve widget order and quick links

This commit is contained in:
David Ralph
2021-04-10 13:05:56 +01:00
parent 7c8c61472e
commit e3a482614c
10 changed files with 99 additions and 26 deletions

View File

@@ -6,12 +6,35 @@ export default class DateWidget extends React.PureComponent {
constructor() {
super();
this.state = {
date: ''
date: '',
weekNumber: ''
};
}
getWeekNumber(date) {
const dateToday = new Date(date.valueOf());
const dayNumber = (dateToday.getDay() + 6) % 7;
dateToday.setDate(dateToday.getDate() - dayNumber + 3);
const firstThursday = dateToday.valueOf();
dateToday.setMonth(0, 1);
if (dateToday.getDay() !== 4) {
dateToday.setMonth(0, 1 + ((4 - dateToday.getDay()) + 7) % 7);
}
this.setState({
weekNumber: `${window.language.widgets.date.week} ${1 + Math.ceil((firstThursday - dateToday) / 604800000)}`
});
}
getDate() {
const date = new Date();
if (localStorage.getItem('weeknumber') === 'true') {
this.getWeekNumber(date);
}
const type = localStorage.getItem('dateType');
if (type === 'short') {
@@ -77,6 +100,6 @@ export default class DateWidget extends React.PureComponent {
}
render() {
return <span style={{ 'textTransform': 'capitalize', 'fontWeight': 'bold' }}>{this.state.date}</span>;
return <span style={{ 'textTransform': 'capitalize', 'fontWeight': 'bold' }}>{this.state.date} <br/> {this.state.weekNumber}</span>;
}
}