Skip to content

Commit

Permalink
使用dayjs库增加时间戳
Browse files Browse the repository at this point in the history
  • Loading branch information
wanmaoor committed Feb 22, 2020
1 parent 1862933 commit 650bd6a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@wanmaoor/giaoui": "^0.0.13",
"core-js": "^3.4.4",
"dayjs": "^1.8.20",
"register-service-worker": "^1.6.2",
"vue": "^2.6.10",
"vue-class-component": "^7.0.2",
Expand Down
18 changes: 17 additions & 1 deletion src/views/Statistics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<TabPanel label="按天" value="day">
<ol>
<li :key="index" v-for="(group, index) in result">
<h2 class="title">{{group.title}}</h2>
<h2 class="title">{{handleTime(group.title)}}</h2>
<ol>
<li :key="item.id" class="record" v-for="item in group.items">
<span>{{tagString(item.tags)}}</span>
Expand All @@ -39,6 +39,7 @@
<script lang="ts">
import {Component, Vue} from "vue-property-decorator"
import {Tab, TabPanel} from "@wanmaoor/giaoui"
import dayjs from "dayjs"
interface IHashTable {
[key: string]: {
Expand Down Expand Up @@ -73,6 +74,21 @@
tagString(tags: IData[]) {
return tags.length === 0 ? "未添加标签" : tags.join(",")
}
handleTime(ISOString: stirng) {
const api = dayjs(ISOString)
if (api.isSame(dayjs(), "day")) {
return "今天"
} else if (api.isSame(dayjs().subtract(1, "day"), "day")) {
return "昨天"
} else if (api.isSame(dayjs().subtract(2, "day"), "day")) {
return "前天"
} else if (api.isSame(dayjs(), "year")) {
return api.format("M月D日")
} else {
return api.format("YYYY年M月D日")
}
}
}
</script>

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3497,6 +3497,11 @@ date-fns@^1.27.2:
resolved "https://registry.npm.taobao.org/date-fns/download/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
integrity sha1-LnG/CxGRU9u0zE6I2epaz7UNwFw=

dayjs@^1.8.20:
version "1.8.20"
resolved "https://registry.npmjs.org/dayjs/-/dayjs-1.8.20.tgz#724a5cb6ad1f6fc066b0bd9a800dedcc7886f19e"
integrity sha512-mH0MCDxw6UCGJYxVN78h8ugWycZAO8thkj3bW6vApL5tS0hQplIDdAQcmbvl7n35H0AKdCJQaArTrIQw2xt4Qg==

de-indent@^1.0.2:
version "1.0.2"
resolved "https://registry.npm.taobao.org/de-indent/download/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"
Expand Down

0 comments on commit 650bd6a

Please sign in to comment.