From 80e01bb1025221e7ecbe75fd910dcddc5cd04580 Mon Sep 17 00:00:00 2001 From: levy <897895407@qq.com> Date: Fri, 18 Oct 2019 11:20:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?chore(ci):=20=E6=88=90=E5=8A=9F=E6=97=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=B8=A6=E4=B8=8A=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=EF=BC=8C=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=B8=8D=E5=AF=B9github?= =?UTF-8?q?=E4=BA=A7=E7=94=9F=E5=89=AF=E4=BD=9C=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 2 -- build.sh | 3 --- notify.sh | 8 +++++++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index baf4eae..486908c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ install: - yarn test script: - ./build.sh -after_success: -- GREN_GITHUB_TOKEN=$GITHUB_TOKEN yarn release after_script: - ./notify.sh cache: yarn diff --git a/build.sh b/build.sh index d4f801d..71653ff 100755 --- a/build.sh +++ b/build.sh @@ -2,6 +2,3 @@ yarn stdver yarn build - -git remote add github https://$GITHUB_TOKEN@github.com/FEMessage/count-down.git > /dev/null 2>&1 -git push github HEAD:master --follow-tags diff --git a/notify.sh b/notify.sh index 2601933..fb012a4 100755 --- a/notify.sh +++ b/notify.sh @@ -5,6 +5,11 @@ then exit 1 fi +git remote add github https://$GITHUB_TOKEN@github.com/FEMessage/count-down.git > /dev/null 2>&1 +git push github HEAD:master --follow-tags + +GREN_GITHUB_TOKEN=$GITHUB_TOKEN yarn release + url=https://api.github.com/repos/FEMessage/count-down/releases/latest resp_tmp_file=resp.tmp @@ -12,8 +17,9 @@ curl -H "Authorization: token $GITHUB_TOKEN" $url > $resp_tmp_file html_url=$(sed -n 5p $resp_tmp_file | sed 's/\"html_url\"://g' | awk -F '"' '{print $2}') body=$(grep body < $resp_tmp_file | sed 's/\"body\"://g;s/\"//g') +version=$(echo $html_url | awk -F '/' '{print $NF}') -msg='{"msgtype": "markdown", "markdown": {"title": "count-down更新", "text": "@所有人\n# [count-down]('$html_url')\n'$body'"}}' +msg='{"msgtype": "markdown", "markdown": {"title": "count-down更新", "text": "@所有人\n# [count-down('$version')]('$html_url')\n'$body'"}}' curl -X POST https://oapi.dingtalk.com/robot/send\?access_token\=$DINGTALK_ROBOT_TOKEN -H 'Content-Type: application/json' -d "$msg" From cd712c632ca64813d78e50876c4953b80f0b64d4 Mon Sep 17 00:00:00 2001 From: Shoyuf Date: Wed, 6 Nov 2019 15:30:04 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(milliseconds):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=AF=AB=E7=A7=92=E5=80=92=E8=AE=A1=E6=97=B6=20(#6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/format.md | 2 +- src/count-down.vue | 15 +++++++++++---- src/util.js | 45 ++++++++++++++++++++++++++++++--------------- test/util.test.js | 12 +++++++----- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/docs/format.md b/docs/format.md index d118d1e..75ca7ab 100644 --- a/docs/format.md +++ b/docs/format.md @@ -2,6 +2,6 @@ custom output format ```vue ``` diff --git a/src/count-down.vue b/src/count-down.vue index efc07e4..9181692 100644 --- a/src/count-down.vue +++ b/src/count-down.vue @@ -38,6 +38,13 @@ export default { type: Number, default: 0 }, + /** + * remain milliseconds + */ + milliseconds: { + type: Number, + default: 0 + }, /** * whether autoplay or not */ @@ -47,13 +54,13 @@ export default { }, /** * Output format. - * Default: 'dd 天 hh 时 mm 分 ss 秒'. These dd, hh, mm & ss specifiers are optional. - * The default value will change according to whether there are days, hours, minutes & seconds, + * Default: 'dd 天 hh 时 mm 分 ss 秒'. These dd, hh, mm, ss & ms specifiers are optional. + * The default value will change according to whether there are days, hours, minutes, seconds & milliseconds, * e.g., if user just pass minutes, then the default value will be 'mm 分 ss 秒' * * 输出格式。 - * 默认值:'dd 天 hh 时 mm 分 ss 秒'。dd、hh、mm和ss标识符都是可选的。 - * 默认值会根据是否传入days, hours, minutes, seconds而变化, + * 默认值:'dd 天 hh 时 mm 分 ss 秒'。dd、hh、mm、ss 和 ms 标识符都是可选的。 + * 默认值会根据是否传入days, hours, minutes, seconds 和 milliseconds而变化, * 比如用户只传了minutes,那么默认值就变为'mm 分 ss 秒' */ format: { diff --git a/src/util.js b/src/util.js index dc3cb53..716095d 100644 --- a/src/util.js +++ b/src/util.js @@ -3,13 +3,15 @@ const formatSpecifiers = { days: 'dd', hours: 'hh', minutes: 'mm', - seconds: 'ss' + seconds: 'ss', + milliseconds: 'ms' } -const secondsIn = { - days: 60 * 60 * 24, - hours: 60 * 60, - minutes: 60, - seconds: 1 +const millisecondsIn = { + days: 60 * 60 * 24 * 1000, + hours: 60 * 60 * 1000, + minutes: 60 * 1000, + seconds: 1 * 1000, + milliseconds: 1 } /** @@ -34,8 +36,23 @@ function padStart(str, len, v) { return str } -function padZero(str) { - return padStart(str + '', 2, '0') +function padZero(str, padRange = 2) { + return padStart(str + '', padRange, '0') +} + +/** + * 天、小时、分钟、秒、毫秒格式化 + * @param {string} key + * @param {number} value + * @returns {string} + */ +function timeFormatter(key, value) { + // 天、时、分、秒两位,毫秒三位 + if (key === 'milliseconds') { + return padZero(value, 3) + } else { + return padZero(value) + } } export function toMilliseconds({ @@ -55,13 +72,12 @@ export function toMilliseconds({ */ export function formatTime(time, format) { let result = format - time = Math.ceil(time / 1000) // 注意顺序很重要。要先从大的时间单位开始构造字符串 entries(formatSpecifiers).forEach(([k, specifier]) => { if (includes(result, specifier)) { - const v = Math.floor(time / secondsIn[k]) - time -= v * secondsIn[k] - result = result.replace(specifier, padZero(v)) + const v = Math.floor(time / millisecondsIn[k]) + time -= v * millisecondsIn[k] + result = result.replace(specifier, timeFormatter(k, v)) } }) return result @@ -73,9 +89,8 @@ export function formatTime(time, format) { * @return 数据对象,包含days, hours, minutes, seconds & milliseconds字段 */ export function toTimeData(time) { - const timeData = {milliseconds: time % 1000} - time /= 1000 - entries(secondsIn).forEach(([k, v]) => { + const timeData = {} + entries(millisecondsIn).forEach(([k, v]) => { timeData[k] = Math.floor(time / v) time -= timeData[k] * v }) diff --git a/test/util.test.js b/test/util.test.js index df2490c..cd31d2e 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -1,21 +1,23 @@ import {formatTime, toTimeData, toMilliseconds} from '../src/util' describe('formatTime', () => { - test('正确解析日时分秒', () => { + test('正确解析日时分秒毫秒', () => { const t = toMilliseconds({ days: 2, hours: 3, minutes: 4, - seconds: 5 + seconds: 5, + milliseconds: 1 }) - expect(formatTime(t, 'ddhhmmss')).toBe('02030405') + expect(formatTime(t, 'ddhhmmssms')).toBe('02030405001') const t2 = toMilliseconds({ days: 2, hours: 33, minutes: 4, - seconds: -5 + seconds: -5, + milliseconds: 1 }) - expect(formatTime(t2, 'ddhhmmss')).toBe('03090355') + expect(formatTime(t2, 'ddhhmmssms')).toBe('03090355001') }) test('format仅传部分占位符的情况', () => { const t = toMilliseconds({ From c517befcf7d5b796f0ad246fab81f6317a846664 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Wed, 6 Nov 2019 15:30:26 +0800 Subject: [PATCH 3/3] docs: add shoyuf as a contributor (#7) --- .all-contributorsrc | 9 +++++++++ README.md | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index d180f59..6907116 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -20,6 +20,15 @@ "doc", "test" ] + }, + { + "login": "shoyuf", + "name": "Shoyuf", + "avatar_url": "https://avatars3.githubusercontent.com/u/27998490?v=4", + "profile": "https://shoyuf.top", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7 diff --git a/README.md b/README.md index e6fd837..07f5bb3 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d -
Donald Shen
Donald Shen

💻 📖 ⚠️
+ + + + + +
Donald Shen
Donald Shen

💻 📖 ⚠️
Shoyuf
Shoyuf

💻