• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alkem-io / client-web / #6829

29 Feb 2024 07:48AM UTC coverage: 5.921%. First build
#6829

Pull #5641

travis-ci

Pull Request #5641: Time indications Contribution logs

189 of 9009 branches covered (2.1%)

Branch coverage included in aggregate %.

1 of 8 new or added lines in 2 files covered. (12.5%)

1324 of 16544 relevant lines covered (8.0%)

0.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
/src/domain/shared/utils/formatTimeElapsed.ts
1
import type { TFunction } from 'i18next';
2

3
const ONE_SECOND = 1000;
1✔
4
const ONE_MINUTE = 60 * ONE_SECOND;
1✔
5
const ONE_HOUR = 60 * ONE_MINUTE;
1✔
6
const ONE_DAY = 24 * ONE_HOUR;
1✔
7
const ONE_MONTH = 31 * ONE_DAY;
1✔
8
const ONE_YEAR = 256 * ONE_DAY;
1✔
9

10
export const formatTimeElapsed = (date: Date | string, t: TFunction, format: 'short' | 'long' = 'short'): string => {
1✔
11
  const currentDate = new Date();
12
  const formatCandidate = new Date(date);
13

×
14
  const diffInTime = Math.max(0, currentDate.getTime() - formatCandidate.getTime());
15

×
16
  if (diffInTime > ONE_YEAR) {
×
17
    const timeDiff = Math.round(diffInTime / ONE_YEAR);
18
    return t(`common.time.${format}.timeAgo` as const, {
×
19
      time: t(`common.time.${format}.year` as const, { count: timeDiff }),
20
    });
×
21
  }
×
NEW
22
  if (diffInTime > ONE_MONTH) {
×
23
    const timeDiff = Math.round(diffInTime / ONE_MONTH);
24
    return t(`common.time.${format}.timeAgo` as const, {
25
      time: t(`common.time.${format}.month` as const, { count: timeDiff }),
26
    });
×
27
  }
×
NEW
28

×
29
  if (diffInTime > ONE_DAY) {
30
    const timeDiff = Math.round(diffInTime / ONE_DAY);
31
    return t(`common.time.${format}.timeAgo` as const, {
32
      time: t(`common.time.${format}.day` as const, { count: timeDiff }),
33
    });
×
34
  }
×
NEW
35

×
36
  if (diffInTime > ONE_HOUR) {
37
    const timeDiff = Math.round(diffInTime / ONE_HOUR);
38
    return t(`common.time.${format}.timeAgo` as const, {
39
      time: t(`common.time.${format}.hour` as const, { count: timeDiff }),
40
    });
×
41
  }
×
NEW
42

×
43
  if (diffInTime > ONE_MINUTE) {
44
    const timeDiff = Math.round(diffInTime / ONE_MINUTE);
45
    return t(`common.time.${format}.timeAgo` as const, {
46
      time: t(`common.time.${format}.minute` as const, { count: timeDiff }),
47
    });
×
48
  }
×
NEW
49

×
50
  const timeDiff = Math.round(diffInTime / ONE_SECOND);
51

52
  if (timeDiff === 0) {
53
    return 'just now';
54
  }
×
55

56
  return t(`common.time.${format}.timeAgo` as const, {
×
57
    time: t(`common.time.${format}.second` as const, { count: timeDiff }),
×
58
  });
59
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc