-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new tools): Date+Duration and Days Calculator
Allows computing specific date + some durations Allows computing Date interval with many options (include end date, select week days, holidays, business time) and output many statistics Fix #778, #584, #971
- Loading branch information
Showing
14 changed files
with
1,736 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/tools/date-duration-calculator/date-duration-calculator.service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { addToDate } from './date-duration-calculator.service'; | ||
|
||
describe('date-duration-calculator', () => { | ||
describe('addToDate', () => { | ||
it('compute right values', () => { | ||
expect(addToDate(new Date('2024-08-15T07:21:46Z'), '+1d 1m 20s')).to.deep.eq( | ||
{ | ||
date: new Date('2024-08-16T07:23:06.000Z'), | ||
durationPretty: '1d 1m 20s', | ||
durationSeconds: 86480, | ||
errors: [], | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
src/tools/date-duration-calculator/date-duration-calculator.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { computeDuration } from '../duration-calculator/duration-calculator.service'; | ||
|
||
export function addToDate(date: Date, durations: string) { | ||
const { total, errors } = computeDuration(durations); | ||
|
||
return { | ||
errors, | ||
date: new Date(date.getTime() + total.milliseconds), | ||
durationSeconds: total.seconds, | ||
durationPretty: total.prettified, | ||
}; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/tools/date-duration-calculator/date-duration-calculator.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script setup lang="ts"> | ||
import { addToDate } from './date-duration-calculator.service'; | ||
const now = Date.now(); | ||
const inputReferenceDate = ref(now); | ||
const inputDurations = ref(''); | ||
const resultDateAdder = computed(() => addToDate(new Date(inputReferenceDate.value), inputDurations.value)); | ||
const errorsDateAdder = computed(() => resultDateAdder.value.errors.join('\n')); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<c-card title="Date + Duration Calculator" mb-2> | ||
<n-form-item label="Reference Date:" label-placement="left" mb-1> | ||
<n-date-picker v-model:value="inputReferenceDate" type="datetime" /> | ||
</n-form-item> | ||
|
||
<c-input-text | ||
v-model:value="inputDurations" | ||
multiline | ||
rows="5" | ||
label="Duration(s)" | ||
placeholder="Please enter duration, one per line with optional sign" | ||
mb-2 | ||
/> | ||
<n-p>Supports: comment (# line), HH:MM:SS.FFF, 3d 1h 3s..., P4DT12H20M20.3S..</n-p> | ||
|
||
<c-card v-if="errorsDateAdder" title="Lines errors"> | ||
<textarea-copyable :value="errorsDateAdder" /> | ||
</c-card> | ||
|
||
<n-divider /> | ||
|
||
<input-copyable v-if="resultDateAdder" label="Result Date:" label-position="left" label-width="150px" :value="resultDateAdder.date.toString()" mb-1 /> | ||
<input-copyable v-if="resultDateAdder" label="Result ISO Date:" label-position="left" label-width="150px" :value="resultDateAdder.date.toISOString()" mb-1 /> | ||
<input-copyable v-if="resultDateAdder" label="Duration (seconds):" label-position="left" label-width="150px" :value="resultDateAdder.durationSeconds" mb-1 /> | ||
<input-copyable v-if="resultDateAdder" label="Duration:" label-position="left" label-width="150px" :value="resultDateAdder.durationPretty" mb-1 /> | ||
</c-card> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Calendar } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Date+Durations Calculator', | ||
path: '/date-duration-calculator', | ||
description: 'Add/substract durations from a specific date', | ||
keywords: ['date', 'duration', 'addition', 'calculator'], | ||
component: () => import('./date-duration-calculator.vue'), | ||
icon: Calendar, | ||
createdAt: new Date('2024-08-15'), | ||
}); |
Oops, something went wrong.