Skip to content

Commit

Permalink
✨ if you are tracking time in hours you can now enter durations in ad…
Browse files Browse the repository at this point in the history
…dition to decimals (e.g. 1:30 instead of 1,5)
  • Loading branch information
faburem committed Feb 1, 2024
1 parent 1aa0464 commit c501bb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion imports/ui/pages/track/tracktime.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FlowRouter } from 'meteor/ostrio:flow-router-extra'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import duration from 'dayjs/plugin/duration'
import bootstrap from 'bootstrap'
import TinyDatePicker from 'tiny-date-picker'
import 'tiny-date-picker/tiny-date-picker.css'
Expand Down Expand Up @@ -75,6 +76,7 @@ Template.tracktime.onCreated(function tracktimeCreated() {
})
dayjs.extend(utc)
dayjs.extend(customParseFormat)
dayjs.extend(duration)
this.date = new ReactiveVar(dayjs().toDate())
this.projectId = new ReactiveVar()
this.tcid = new ReactiveVar()
Expand Down Expand Up @@ -166,7 +168,14 @@ Template.tracktime.events({
showToast(t('notifications.enter_task'))
return
}
if (!hours && hours !== 0 && !Number.isNaN(hours)) {
if (hours?.includes(':')) {
const { 0: hoursString, 1: minutesString } = hours.split(':')
const duration = dayjs.duration({
hours: Number.parseInt(hoursString, 10),
minutes: Number.parseInt(minutesString, 10),
})
hours = duration.asHours().toString()
} else if (!hours && hours !== 0 && !Number.isNaN(hours)) {
templateInstance.$('#hours').addClass('is-invalid')
showToast(t('notifications.enter_time'))
return
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "titra",
"version": "0.96.3",
"version": "0.96.4",
"private": true,
"scripts": {
"start": "meteor run"
Expand Down

0 comments on commit c501bb5

Please sign in to comment.