egirlskey/src/web/app/common/tags/time.tag

42 lines
1.4 KiB
Plaintext
Raw Normal View History

2017-01-11 20:55:38 +00:00
<mk-time>
<time datetime="{ opts.time }"><span if="{ mode == 'relative' }">{ relative }</span><span if="{ mode == 'absolute' }">{ absolute }</span><span if="{ mode == 'detail' }">{ absolute } ({ relative })</span></time>
<script>
@time = new Date @opts.time
@mode = @opts.mode || \relative
@tickid = null
2016-12-28 22:49:51 +00:00
2017-01-11 20:55:38 +00:00
@absolute =
@time.get-full-year! + \年 +
@time.get-month! + 1 + \月 +
@time.get-date! + \日 +
' ' +
@time.get-hours! + \時 +
@time.get-minutes! + \分
2016-12-28 22:49:51 +00:00
2017-01-11 20:55:38 +00:00
@on \mount ~>
if @mode == \relative or @mode == \detail
@tick!
@tickid = set-interval @tick, 1000ms
2016-12-28 22:49:51 +00:00
2017-01-11 20:55:38 +00:00
@on \unmount ~>
if @mode == \relative or @mode == \detail
clear-interval @tickid
2016-12-28 22:49:51 +00:00
2017-01-11 20:55:38 +00:00
@tick = ~>
now = new Date!
ago = (now - @time) / 1000ms
@relative = switch
| ago >= 31536000s => ~~(ago / 31536000s) + '年前'
| ago >= 2592000s => ~~(ago / 2592000s) + 'ヶ月前'
| ago >= 604800s => ~~(ago / 604800s) + '週間前'
| ago >= 86400s => ~~(ago / 86400s) + '日前'
| ago >= 3600s => ~~(ago / 3600s) + '時間前'
| ago >= 60s => ~~(ago / 60s) + '分前'
| ago >= 10s => ~~(ago % 60s) + '秒前'
| ago >= 0s => 'たった今'
| ago < 0s => '未来'
| _ => 'なぞのじかん'
@update!
</script>
</mk-time>