appstore/dist/lib/ui/views/time.js

2 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2023-12-19 15:30:29 +08:00
import{css as u,Component as c}from"wkit";const a=60*1e3,s=a*60,$=s*6,o=s*24,f=o*2,g=o*7,i=new Date().setHours(0,0,0,0),D=new Date(new Date().getFullYear(),0,1,0,0,0,0),h=new Date(new Date().getFullYear()-1,0,1,0,0,0,0);class m extends c{static props={stamp:"num!0"};get#t(){let n=new Date().setMilliseconds(0),t=this.stamp||n,e;if((t+"").length===10&&(t*=1e3),e=new Date(t),this.title=e.toLocaleString(),t>n-a)return"\u521A\u521A";if(t>n-s)return`${~~(t/a)}\u5206\u949F\u524D`;if(t>n-$)return`${~~(t/s)}\u5C0F\u65F6\u524D`;if(t>=i-f){let r=e.getHours(),l=r<6?"\u51CC\u6668":r<12?"\u4E0A\u5348":r>18?"\u665A\u4E0A":"\u4E0B\u5348";return t>=i?`${l}${r%12}\u70B9${e.getMinutes()}\u5206`:t>=i-o?`\u6628\u5929${l}${r%12}\u70B9`:`\u524D\u5929${l}`}return t>=i-g?`${~~((n-t)/o)}\u5929\u524D`:t>D?`${e.getMonth()+1}\u6708${e.getDate()}\u65E5`:t>h?`\u53BB\u5E74${e.getMonth()+1}\u6708${e.getDate()}\u65E5`:`${e.getFullYear()}\u5E74${e.getMonth()+1}\u6708`}static styles=[u`:host{display:inline-flex;font-size:12px;color:var(--color-dark-1);-webkit-user-select:none;user-select:none;cursor:default}`];render(){return this.#t}}m.reg("time");