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

nodeplusplus / xregex-filter / 299

pending completion
299

Pull #16

circleci

Unknown Committer
Unknown Commit Message
Pull Request #16: Bump json5 from 2.1.2 to 2.2.3

299 of 299 branches covered (100.0%)

Branch coverage included in aggregate %.

293 of 293 relevant lines covered (100.0%)

8.84 hits per line

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

100.0
/src/filters/datetime/parseRelativeTime.ts
1
import moment from "moment";
4✔
2

3
import { IXFilterFunction } from "../../types/XFilter";
4

5
const parseRelativeTime: IXFilterFunction<
6
  string,
7
  any,
8
  IXFilterFunctionParseRelativeTimeOpts
9
> = function parseRelativeTime(
4✔
10
  payload: any,
11
  opts?: IXFilterFunctionParseRelativeTimeOpts
12
): string {
13
  if (!payload || typeof payload !== "string") return payload;
15✔
14
  if (!opts || !opts.pattern) return payload;
12✔
15

16
  // Cleanup first
17
  const datetime = payload.toLowerCase().trim().replace(/\s\s+/g, " ");
10✔
18
  if (!datetime) return payload;
10✔
19

20
  const { pattern, unitsMap } = opts;
8✔
21

22
  const matched = datetime.match(pattern);
8✔
23
  if (!matched || !matched[2]) return payload;
8✔
24

25
  const time = Number(matched[1]);
5✔
26
  const unit = unitsMap ? unitsMap[matched[2]] : matched[2];
5✔
27
  if (!time || !unit) return payload;
5✔
28

29
  return moment()
2✔
30
    .subtract(time, unit as any)
31
    .toISOString();
32
};
33

34
export default parseRelativeTime;
4✔
35
export interface IXFilterFunctionParseRelativeTimeOpts {
36
  pattern: string;
37
  unitsMap?: {
38
    [name: string]: IXFilterParseRelativeTimeUnits;
39
  };
40
}
41
export type IXFilterParseRelativeTimeUnits =
42
  | "s"
43
  | "ss"
44
  | "m"
45
  | "mm"
46
  | "h"
47
  | "hh"
48
  | "d"
49
  | "dd"
50
  | "M"
51
  | "MM"
52
  | "y"
53
  | "yy";
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