Fix 'last month' link option

Fixes #898
This commit is contained in:
Uku Taht 2021-03-31 15:13:58 +03:00
parent 4cbebe8ac9
commit 3e33385afd
3 changed files with 10 additions and 6 deletions

View File

@ -7,8 +7,12 @@ export function formatISO(date) {
export function shiftMonths(date, months) {
const newDate = new Date(date.getTime())
newDate.setMonth(newDate.getMonth() + months)
return newDate
const d = newDate.getDate();
newDate.setMonth(newDate.getMonth() + +months);
if (newDate.getDate() != d) {
newDate.setDate(0);
}
return newDate;
}
export function shiftDays(date, days) {

View File

@ -294,7 +294,7 @@ class DatePicker extends React.Component {
boldClass = query.period === period ? "font-bold" : "";
}
const date = opts.date ? formatISO(opts.date) : false;
opts.date = opts.date ? formatISO(opts.date) : false;
const keybinds = {
'Today': 'D',
@ -308,7 +308,7 @@ class DatePicker extends React.Component {
return (
<QueryLink
to={{from: false, to: false, date, period, ...opts}}
to={{from: false, to: false, period, ...opts}}
onClick={this.close.bind(this)}
query={this.props.query}
className={`${boldClass } px-4 py-2 md:text-sm leading-tight hover:bg-gray-100

View File

@ -79,8 +79,8 @@ export function navigateToQuery(history, queryFrom, newData) {
}
class QueryLink extends React.Component {
constructor() {
super()
constructor(props) {
super(props)
this.onClick = this.onClick.bind(this)
}