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

Haixing-Hu / js-common-filter / 356ebe30-cf35-4a83-a73d-a562aa4590b5

26 Mar 2024 04:09AM UTC coverage: 90.476% (-2.9%) from 93.366%
356ebe30-cf35-4a83-a73d-a562aa4590b5

push

circleci

Haixing-Hu
feat: add some datetime format functions

192 of 212 branches covered (90.57%)

Branch coverage included in aggregate %.

0 of 6 new or added lines in 2 files covered. (0.0%)

188 of 208 relevant lines covered (90.38%)

17.59 hits per line

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

0.0
/src/datetime-with-pattern.js
1
////////////////////////////////////////////////////////////////////////////////
2
//
3
//    Copyright (c) 2022 - 2023.
4
//    Haixing Hu, Qubit Co. Ltd.
5
//
6
//    All rights reserved.
7
//
8
////////////////////////////////////////////////////////////////////////////////
9
import toDayjs from './impl/to-dayjs';
10

11
/**
12
 * Formats a date time in the specified time zone and reserve only its date
13
 * and time part.
14
 *
15
 * @param {string|Date} dateTime
16
 *     a datetime value, either a string in the ISO-8601 format, or a {@link Date}
17
 *     object.
18
 * @param {string} pattern
19
 *     the format patter, default value is 'YYYY-MM-DD HH:mm:ss'.
20
 * @param {string|undefined} tz
21
 *     the specified timezone. If it is `undefined`, or `null`, or empty strings,
22
 *     the local timezone is used. Default value of this argument is `undefined`.
23
 * @returns {string|null}
24
 *     the date time part of the formatted date time, in the predefined format.
25
 *     If the input is `null` or `undefined` or empty string, this function
26
 *     returns `null`.
27
 * @author Haixing Hu
28
 */
29
function formatDatetimeWithPattern(dateTime, pattern = 'YYYY-MM-DD HH:mm:ss', tz = undefined) {
×
NEW
30
  if (dateTime) {
×
NEW
31
    return toDayjs(dateTime, tz).format(pattern);
×
32
  } else {
NEW
33
    return null;
×
34
  }
35
}
36

37
export default formatDatetimeWithPattern;
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

© 2025 Coveralls, Inc