mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-07 14:57:12 -04:00
parent
cfa2502201
commit
3d4ee138ad
3 changed files with 58 additions and 7 deletions
|
@ -65,6 +65,17 @@ describe('days-calculator', () => {
|
|||
type: 'public',
|
||||
},
|
||||
];
|
||||
const totalDiff1 = {
|
||||
totalDifference: {
|
||||
days: 30.416666666666668,
|
||||
hours: 730,
|
||||
minutes: 43800,
|
||||
months: 0.9811827956989247,
|
||||
seconds: 2628000,
|
||||
weeks: 4.345238095238095,
|
||||
years: 0.08333333333333333,
|
||||
},
|
||||
};
|
||||
|
||||
const date1 = new Date('2024-08-01T07:21:46Z');
|
||||
const date2 = new Date('2024-08-31T17:21:46Z');
|
||||
|
@ -88,8 +99,8 @@ describe('days-calculator', () => {
|
|||
businessSecondsFormatted: '11d 5h 38m 14s',
|
||||
differenceFormatted: '29d 10h',
|
||||
differenceSeconds: 2541600,
|
||||
...totalDiff1,
|
||||
totalDifferenceFormatted: '30d 10h',
|
||||
totalDifferenceSeconds: 2628000,
|
||||
holidays,
|
||||
...daysInfos,
|
||||
});
|
||||
|
@ -112,8 +123,16 @@ describe('days-calculator', () => {
|
|||
businessSecondsFormatted: '10d 20h 38m 14.9s',
|
||||
differenceFormatted: '28d 16h 38m 13.9s',
|
||||
differenceSeconds: 2479093.999,
|
||||
totalDifference: {
|
||||
days: 29.69321758101852,
|
||||
hours: 712.6372219444445,
|
||||
minutes: 42758.233316666665,
|
||||
months: 0.9578457284199522,
|
||||
seconds: 2565493.999,
|
||||
weeks: 4.241888225859788,
|
||||
years: 0.08135128104388635,
|
||||
},
|
||||
totalDifferenceFormatted: '29d 16h 38m 13.9s',
|
||||
totalDifferenceSeconds: 2565493.999,
|
||||
holidays,
|
||||
...daysInfos,
|
||||
saturdays: [
|
||||
|
@ -142,8 +161,8 @@ describe('days-calculator', () => {
|
|||
businessSecondsFormatted: '8d 5h 38m 14s',
|
||||
differenceFormatted: '21d 14h 38m 14s',
|
||||
differenceSeconds: 1867094,
|
||||
...totalDiff1,
|
||||
totalDifferenceFormatted: '30d 10h',
|
||||
totalDifferenceSeconds: 2628000,
|
||||
holidays,
|
||||
...daysInfos,
|
||||
});
|
||||
|
@ -167,7 +186,7 @@ describe('days-calculator', () => {
|
|||
differenceFormatted: '4d',
|
||||
differenceSeconds: 345600,
|
||||
totalDifferenceFormatted: '30d 10h',
|
||||
totalDifferenceSeconds: 2628000,
|
||||
...totalDiff1,
|
||||
holidays,
|
||||
...daysInfos,
|
||||
});
|
||||
|
|
|
@ -7,7 +7,15 @@ import { BusinessTime, type Holiday } from './business-time-calculator';
|
|||
interface DateTimeRange {
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
totalDifferenceSeconds: number
|
||||
totalDifference: {
|
||||
years: number
|
||||
months: number
|
||||
weeks: number
|
||||
days: number
|
||||
hours: number
|
||||
minutes: number
|
||||
seconds: number
|
||||
}
|
||||
totalDifferenceFormatted: string
|
||||
differenceSeconds: number
|
||||
differenceFormatted: string
|
||||
|
@ -96,6 +104,12 @@ export function diffDateTimes({
|
|||
const startEnd = { start: startDateTime, end: endDateTime };
|
||||
|
||||
const totalDifferenceSeconds = endDateTime.diff(startDateTime, 'seconds').toObject().seconds || 0;
|
||||
const totalDifferenceMinutes = endDateTime.diff(startDateTime, 'minutes').toObject().minutes || 0;
|
||||
const totalDifferenceHours = endDateTime.diff(startDateTime, 'hours').toObject().hours || 0;
|
||||
const totalDifferenceDays = endDateTime.diff(startDateTime, 'days').toObject().days || 0;
|
||||
const totalDifferenceWeeks = endDateTime.diff(startDateTime, 'weeks').toObject().weeks || 0;
|
||||
const totalDifferenceMonths = endDateTime.diff(startDateTime, 'months').toObject().months || 0;
|
||||
const totalDifferenceYears = endDateTime.diff(startDateTime, 'years').toObject().years || 0;
|
||||
const differenceSeconds = differenceTimeComputer.computeBusinessSecondsInInterval(startEnd);
|
||||
const businessSeconds = businessTimeComputer.computeBusinessSecondsInInterval(startEnd);
|
||||
const weekDaysDates = datesByDays(startDateTime, endDateTime);
|
||||
|
@ -103,7 +117,15 @@ export function diffDateTimes({
|
|||
return {
|
||||
startDate: startDateTime.toJSDate(),
|
||||
endDate: endDateTime.toJSDate(),
|
||||
totalDifferenceSeconds,
|
||||
totalDifference: {
|
||||
years: totalDifferenceYears,
|
||||
months: totalDifferenceMonths,
|
||||
weeks: totalDifferenceWeeks,
|
||||
days: totalDifferenceDays,
|
||||
hours: totalDifferenceHours,
|
||||
minutes: totalDifferenceMinutes,
|
||||
seconds: totalDifferenceSeconds,
|
||||
},
|
||||
totalDifferenceFormatted: prettyMilliseconds(totalDifferenceSeconds * 1000),
|
||||
differenceSeconds,
|
||||
differenceFormatted: prettyMilliseconds(differenceSeconds * 1000),
|
||||
|
|
|
@ -146,14 +146,23 @@ const inputProps = {
|
|||
<input-copyable v-bind="inputProps" label="End Date" :value="resultDaysDiff.endDate" />
|
||||
<input-copyable v-bind="inputProps" label="End Date (ISO)" :value="resultDaysDiff.endDate.toISOString()" />
|
||||
<n-divider />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Seconds" :value="resultDaysDiff.totalDifferenceSeconds" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Seconds" :value="resultDaysDiff.totalDifference.seconds" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Minutes" :value="resultDaysDiff.totalDifference.minutes" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Hours" :value="resultDaysDiff.totalDifference.hours" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Days" :value="resultDaysDiff.totalDifference.days" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Weeks" :value="resultDaysDiff.totalDifference.weeks" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Months" :value="resultDaysDiff.totalDifference.months" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference Years" :value="resultDaysDiff.totalDifference.years" />
|
||||
<input-copyable v-bind="inputProps" label="Total Difference" :value="resultDaysDiff.totalDifferenceFormatted" />
|
||||
<n-divider />
|
||||
<input-copyable v-bind="inputProps" label="Difference Seconds" :value="resultDaysDiff.differenceSeconds" />
|
||||
<input-copyable v-bind="inputProps" label="Difference " :value="resultDaysDiff.differenceFormatted" />
|
||||
<n-divider />
|
||||
<input-copyable v-bind="inputProps" label="Business Seconds" :value="resultDaysDiff.businessSeconds" />
|
||||
<input-copyable v-bind="inputProps" label="Business Time" :value="resultDaysDiff.businessSecondsFormatted" />
|
||||
<input-copyable v-bind="inputProps" label="Business Hours" :value="resultDaysDiff.businessHours" />
|
||||
<input-copyable v-bind="inputProps" label="Business Days" :value="resultDaysDiff.businessDays" />
|
||||
<n-divider />
|
||||
<input-copyable v-bind="inputProps" placeholder="None" label="Mondays" :value="resultDaysDiff.mondays" />
|
||||
<input-copyable v-bind="inputProps" placeholder="None" label="Tuesdays" :value="resultDaysDiff.tuesdays" />
|
||||
<input-copyable v-bind="inputProps" placeholder="None" label="Wednesdays" :value="resultDaysDiff.wednesdays" />
|
||||
|
@ -161,6 +170,7 @@ const inputProps = {
|
|||
<input-copyable v-bind="inputProps" placeholder="None" label="Fridays" :value="resultDaysDiff.fridays" />
|
||||
<input-copyable v-bind="inputProps" placeholder="None" label="Saturdays" :value="resultDaysDiff.saturdays" />
|
||||
<input-copyable v-bind="inputProps" placeholder="None" label="Sundays" :value="resultDaysDiff.sundays" />
|
||||
<n-divider />
|
||||
<input-copyable v-bind="inputProps" label="Weekend Days" :value="resultDaysDiff.weekendDays" />
|
||||
<input-copyable v-bind="inputProps" label="Full Weekends" :value="resultDaysDiff.weekends" />
|
||||
<c-card v-if="resultDaysDiff.holidays?.length" title="Holidays in period">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue