diff --git a/api/quotes.go b/api/quotes.go index e3b43d6..cdc622f 100644 --- a/api/quotes.go +++ b/api/quotes.go @@ -10,11 +10,9 @@ import ( func declareQuotesRoutes(cfg *config.Config, router *gin.RouterGroup) { router.GET("/quoteoftheday", func(c *gin.Context) { - }) router.GET("/quotes", func(c *gin.Context) { - }) router.POST("/quotes", func(c *gin.Context) { diff --git a/model/alarm.go b/model/alarm.go index 0d6f1c3..d9ca714 100644 --- a/model/alarm.go +++ b/model/alarm.go @@ -57,8 +57,9 @@ func GetNextAlarm(db *LevelDBStorage) (*time.Time, error) { return nil, err } + now := time.Now() for _, alarm := range alarmsSingle { - if closestAlarm == nil || closestAlarm.After(alarm.Time) { + if closestAlarm == nil || (closestAlarm.After(alarm.Time) && alarm.Time.After(now)) { closestAlarm = &alarm.Time } } diff --git a/ui/src/components/CycleCounter.svelte b/ui/src/components/CycleCounter.svelte new file mode 100644 index 0000000..f3fac60 --- /dev/null +++ b/ui/src/components/CycleCounter.svelte @@ -0,0 +1,35 @@ + + +{#if begins && ends} + + (dans {Math.trunc((ends.getTime()-begins.getTime())/5400000)} cycles + {Math.trunc(((ends.getTime()-begins.getTime())%5400000)/60000)} min) + +{/if} diff --git a/ui/src/routes/+page.svelte b/ui/src/routes/+page.svelte index 981d1c7..81b15db 100644 --- a/ui/src/routes/+page.svelte +++ b/ui/src/routes/+page.svelte @@ -4,6 +4,7 @@ Icon, } from 'sveltestrap'; + import CycleCounter from '../components/CycleCounter.svelte'; import DateFormat from '../components/DateFormat.svelte'; import { getNextAlarm, newNCyclesAlarm } from '../lib/alarmsingle'; import { alarmsSingle } from '../stores/alarmsingle'; @@ -11,11 +12,13 @@ let nextAlarmP = getNextAlarm(); + function reloadNextAlarm() { + nextAlarmP = getNextAlarm(); + alarmsSingle.clear(); + } + function newCyclesAlarm(ncycles) { - newNCyclesAlarm(ncycles).then(() => { - nextAlarmP = getNextAlarm(); - alarmsSingle.clear(); - }) + newNCyclesAlarm(ncycles).then(reloadNextAlarm); } @@ -44,12 +47,12 @@ aujourd'hui à
- (dans {Math.trunc((nextalarm.getTime()-Date.now())/5400000)} cycles + {Math.trunc(((nextalarm.getTime()-Date.now())%5400000)/60000)} min) + {:else if nextalarm.getDay() == new Date(Date.now() + 86400000).getDay() && nextalarm.getMonth() == new Date(Date.now() + 86400000).getMonth() && nextalarm.getFullYear() == new Date(Date.now() + 86400000).getFullYear()} demain à
- (dans {Math.trunc((nextalarm.getTime()-Date.now())/5400000)} cycles + {Math.trunc(((nextalarm.getTime()-Date.now())%5400000)/60000)} min) + {:else if nextalarm.getTime() < Date.now() + 604800000} {nextalarm.toLocaleString('default', {weekday: 'long'})} à