Skip to content

Commit

Permalink
fix: Improve route "codeforces" time expression readability (DIYgod#1…
Browse files Browse the repository at this point in the history
…1953)

* Improve time expression readablity

* Fix lint issues

* use dayjs
  • Loading branch information
Bubbu0129 authored Feb 26, 2023
1 parent aefd309 commit 4698900
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 13 additions & 5 deletions lib/v2/codeforces/contests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const got = require('@/utils/got');
const path = require('path');
const { art } = require('@/utils/render');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

const dayjs = require('dayjs');
dayjs.extend(require('dayjs/plugin/localizedFormat'));
dayjs.extend(require('dayjs/plugin/duration'));
dayjs.extend(require('dayjs/plugin/relativeTime'));
require('dayjs/locale/zh-cn');
dayjs.locale('zh-cn');

const sec2str = (sec) => dayjs.duration(parseInt(sec), 'seconds').humanize();

const contestAPI = 'https://codeforces.com/api/contest.list';

Expand All @@ -14,11 +21,12 @@ module.exports = async (ctx) => {
.filter((contests) => contests.phase === 'BEFORE')
.map((contest) => {
const title = String(contest.name);
const date = dayjs.unix(parseInt(contest.startTimeSeconds));
const description = art(path.join(__dirname, 'templates/contest.art'), {
title,
startTime: timezone(parseDate(contest.startTimeSeconds * 1000), +0),
durationTime: contest.durationSeconds / 60,
relativeTime: Math.floor(contest.relativeTimeSeconds / 60),
startTime: date.format('LL LT'),
durationTime: sec2str(contest.durationSeconds),
// relativeTime: sec2str(contest.relativeTimeSeconds),
type: contest.type,
});

Expand Down
5 changes: 2 additions & 3 deletions lib/v2/codeforces/templates/contest.art
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<p>比赛:{{ title }}</p>
<p>开始时间:{{ startTime }}</p>
<p>持续时间:{{ durationTime }} 分钟</p>
<p>相对时间:{{ relativeTime }} 分钟</p>
<p>持续时间:{{ durationTime }}</p>
<!-- <p>相对时间:{{ relativeTime }}</p> -->
<p>比赛类型:{{ type }}</p>

0 comments on commit 4698900

Please sign in to comment.