1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: bug in same day comparison

This commit is contained in:
Ferdinand Mütsch 2022-07-02 00:28:56 +02:00
parent a0f69a371f
commit c5da5e4622
2 changed files with 13 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package services package services
import ( import (
"github.com/duke-git/lancet/v2/datetime"
"github.com/duke-git/lancet/v2/mathutil" "github.com/duke-git/lancet/v2/mathutil"
"github.com/muety/wakapi/config" "github.com/muety/wakapi/config"
"github.com/muety/wakapi/models" "github.com/muety/wakapi/models"
@ -60,7 +61,7 @@ func (srv *DurationService) Get(from, to time.Time, user *models.User, filters *
continue continue
} }
sameDay := d1.Time.T().Day() == latest.Time.T().Day() sameDay := datetime.BeginOfDay(d1.Time.T()) == datetime.BeginOfDay(latest.Time.T())
dur := time.Duration(mathutil.Min( dur := time.Duration(mathutil.Min(
int64(d1.Time.T().Sub(latest.Time.T().Add(latest.Duration))), int64(d1.Time.T().Sub(latest.Time.T().Add(latest.Duration))),
int64(HeartbeatDiffThreshold), int64(HeartbeatDiffThreshold),

View File

@ -996,7 +996,7 @@
"header": [], "header": [],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "[{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": 1640995199\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": 1641074399\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": 1641081599\n}]", "raw": "[{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": 1640995200\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": 1641074400\n},\n{\n \"entity\": \"/home/user1/dev/project1/main.go\",\n \"project\": \"wakapi\",\n \"language\": \"Go\",\n \"is_write\": true,\n \"type\": \"file\",\n \"category\": null,\n \"branch\": null,\n \"time\": 1641081600\n}]",
"options": { "options": {
"raw": { "raw": {
"language": "json" "language": "json"
@ -3388,9 +3388,9 @@
"", "",
"getUtcOffset((utcOffset) => {", "getUtcOffset((utcOffset) => {",
" const now = moment().utcOffset(utcOffset)", " const now = moment().utcOffset(utcOffset)",
" const startOfDay = moment().utcOffset(utcOffset).startOf('day')", " const startOfDay = now.clone().startOf('day')",
" const endOfDay = moment().utcOffset(utcOffset).endOf('day')", " const endOfDay = now.clone().endOf('day')",
" const endOfTomorrow = moment().utcOffset(utcOffset).add(1, 'd').endOf('day')", " const endOfTomorrow = now.clone().add(1, 'd').endOf('day')",
"", "",
" // Auth stuff", " // Auth stuff",
" const readApiKey = pm.variables.get('READUSER_API_KEY')", " const readApiKey = pm.variables.get('READUSER_API_KEY')",
@ -3410,19 +3410,19 @@
" }", " }",
"", "",
" // Heartbeat stuff", " // Heartbeat stuff",
" pm.variables.set('tsNow', now.format('x') / 1000)", " pm.variables.set('tsNow', now.clone().format('x') / 1000)",
" pm.variables.set('tsNowMinus1Min', now.add(-1, 'm').format('x') / 1000)", " pm.variables.set('tsNowMinus1Min', now.clone().add(-1, 'm').format('x') / 1000)",
" pm.variables.set('tsNowMinus2Min', now.add(-2, 'm').format('x') / 1000)", " pm.variables.set('tsNowMinus2Min', now.clone().add(-2, 'm').format('x') / 1000)",
" pm.variables.set('tsNowMinus3Min', now.add(-3, 'm').format('x') / 1000)", " pm.variables.set('tsNowMinus3Min', now.clone().add(-3, 'm').format('x') / 1000)",
" pm.variables.set('tsStartOfDay', startOfDay.format('x') / 1000)", " pm.variables.set('tsStartOfDay', startOfDay.format('x') / 1000)",
" pm.variables.set('tsEndOfDay', endOfDay.format('x') / 1000)", " pm.variables.set('tsEndOfDay', endOfDay.format('x') / 1000)",
" pm.variables.set('tsEndOfTomorrow', endOfTomorrow.format('x') / 1000)", " pm.variables.set('tsEndOfTomorrow', endOfTomorrow.format('x') / 1000)",
" pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())", " pm.variables.set('tsStartOfDayIso', startOfDay.toISOString())",
" pm.variables.set('tsEndOfDayIso', endOfDay.toISOString())", " pm.variables.set('tsEndOfDayIso', endOfDay.toISOString())",
" pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())", " pm.variables.set('tsEndOfTomorrowIso', endOfTomorrow.toISOString())",
" pm.variables.set('ts1', now.startOf('hour').format('x') / 1000)", " pm.variables.set('ts1', now.clone().startOf('hour').format('x') / 1000)",
" pm.variables.set('ts2', now.startOf('hour').add(1, 'm').format('x') / 1000)", " pm.variables.set('ts2', now.clone().startOf('hour').add(1, 'm').format('x') / 1000)",
" pm.variables.set('ts3', now.startOf('hour').add(2, 'm').format('x') / 1000)", " pm.variables.set('ts3', now.clone().startOf('hour').add(2, 'm').format('x') / 1000)",
"})" "})"
] ]
} }