Skip to content

Commit 03285ab

Browse files
committed
Display detailed d:h:m duration schedule on campaigns page. Closes #2460.
1 parent 3895fbd commit 03285ab

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

frontend/src/utils.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import {
55
import dayjs from 'dayjs';
66
import relativeTime from 'dayjs/plugin/relativeTime';
77
import updateLocale from 'dayjs/plugin/updateLocale';
8+
import duration from 'dayjs/plugin/duration';
89

910
dayjs.extend(updateLocale);
1011
dayjs.extend(relativeTime);
12+
dayjs.extend(duration);
1113

1214
const reEmail = /(.+?)@(.+?)/ig;
1315
const prefKey = 'listmonk_pref';
@@ -71,11 +73,15 @@ export default class Utils {
7173
duration = (start, end) => {
7274
const a = dayjs(start);
7375
const b = dayjs(end);
76+
const d = dayjs.duration(Math.abs(b.diff(a)));
7477

75-
// Get the duration string, eg: "2 days".
76-
const diff = b.from(a, true);
78+
const parts = [
79+
Math.floor(d.asDays()) && `${Math.floor(d.asDays())}d`,
80+
d.hours() && `${d.hours()}h`,
81+
d.minutes() && `${d.minutes()}m`,
82+
].filter(Boolean);
7783

78-
return `${b.isBefore(a) ? '-' : ''}${diff}`;
84+
return `${b.isBefore(a) ? '-' : ''}${parts.join(' ')}`;
7985
};
8086

8187
// Simple, naive, e-mail address check.

frontend/src/views/Campaigns.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@
145145
<label for="#"><b-icon icon="speedometer" size="is-small" /></label>
146146
<span class="send-rate">
147147
<b-tooltip
148-
:label="`${stats.netRate} / ${$t('campaigns.rateMinuteShort')} @
149-
${$utils.duration(stats.startedAt, stats.updatedAt)}`"
148+
:label="`${stats.netRate} / ${$t('campaigns.rateMinuteShort')} @ ${$utils.duration(stats.startedAt, stats.updatedAt)}`"
150149
type="is-dark">
151150
{{ stats.rate.toFixed(0) }} / {{ $t('campaigns.rateMinuteShort') }}
152151
</b-tooltip>

0 commit comments

Comments
 (0)