Skip to content

Commit

Permalink
use date-fns for the same like new Date :)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelGeo committed Jan 24, 2025
1 parent c2fb398 commit a90504c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
4 changes: 2 additions & 2 deletions server/mergin/stats/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def download_report(date_from: str, date_to: str):
.order_by(MerginStatistics.created_at.desc())
.all()
)
createdColumn = "created_at"
created_column = "created_at"
data = [
{
**stat.data,
"created_at": datetime.isoformat(stat.created_at),
}
for stat in stats
]
columns = list(ServerCallhomeData.__dataclass_fields__.keys()) + [createdColumn]
columns = list(ServerCallhomeData.__dataclass_fields__.keys()) + [created_column]
# get columns for data, this is usefull when we will update data json format (removing columns, adding new ones)

builder = CsvTextBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@
</template>

<script lang="ts" setup>
import {
AppDropdown,
dateUtils,
DropdownOption,
useDialogStore
} from '@mergin/lib'
import { AppDropdown, DropdownOption, useDialogStore } from '@mergin/lib'
import subMonths from 'date-fns/subMonths'
import { ref, watchEffect } from 'vue'
import { useAdminStore } from '@/main'
Expand All @@ -66,7 +62,7 @@ const periodOptions = ref<DropdownOption[]>([
{ label: 'Custom range', value: '-1' }
])
const range = ref<Array<Date>>([
dateUtils.getDateFromMonthsAgo(Number(period.value)),
subMonths(new Date(), Number(period.value)),
new Date()
])
Expand All @@ -76,7 +72,7 @@ watchEffect(() => {
range.value = []
return
}
range.value = [dateUtils.getDateFromMonthsAgo(periodValue), new Date()]
range.value = [subMonths(new Date(), periodValue), new Date()]
})
function close() {
Expand Down
10 changes: 0 additions & 10 deletions web-app/packages/lib/src/common/date_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,3 @@ export function formatRemainingTime(t2, t1 = new Date()) {
return remainingFormatDuration(days, 'days')
}
}

/**
* Calculates date from today to given months number in past.
* Doest not convert to UTC.
*/
export function getDateFromMonthsAgo(months) {
const date = new Date()
date.setMonth(date.getMonth() - months)
return date
}

0 comments on commit a90504c

Please sign in to comment.