How to use dayjs

Comprehensive dayjs code examples:

How to use dayjs.locale:

47
48
49
50
51
52
53
54
55
56
    require(`dayjs/locale/${lang}`);
    if (/^zh/.test(lang)) {
        removeStr = removeStr.concat([',']);
    }
    // Add locale
    dayjs.locale(lang);
} catch (error) {
    logger.error(`Locale "${lang}" passed to dateParser is not supported by dayjs`);
    return date(html);
}

How to use dayjs.unix:

120
121
122
123
124
125
126
127
128
129
            ? "http:".concat(result.pic)
            : result.pic,
        description: result.description,
        duration: durationToSec(result.duration),
        tags: (_j = result.tag) === null || _j === void 0 ? void 0 : _j.split(","),
        date: dayjs.unix(result.pubdate || result.created).format("YYYY-MM-DD"),
    };
}
async function searchAlbum(keyword, page) {
    const resultData = await searchBase(keyword, page, "video");

How to use dayjs.duration:

122
123
124
125
126
127
128
129
130
131
  await datasetUtils.updateStorage(db, dataset)
}

// manage history TTL
if (dataset.rest.historyTTL && dataset.rest.historyTTL.active && dataset.rest.historyTTL.delay && dataset.rest.historyTTL.delay.value) {
  const expireAfterSeconds = dayjs.duration(dataset.rest.historyTTL.delay.value, dataset.rest.historyTTL.delay.unit || 'days').asSeconds()
  await revisionsCollection.createIndex({ _updatedAt: 1 }, { expireAfterSeconds, name: 'history-ttl' })
} else {
  try {
    await revisionsCollection.dropIndex('history-ttl')

How to use dayjs.utc:

18
19
20
21
22
23
24
25
26
27
const semver = require('semver');
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
dayjs.extend(utc);

const timestamp = dayjs.utc().format('YYYYMMDDHHmmss');

const lernaDirectory = path.resolve('.');
const lernaConfigFile = path.resolve(lernaDirectory, 'lerna.json');
const lernaConfig = require(lernaConfigFile);