-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.vue
146 lines (134 loc) · 4.69 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<template>
<div>
<h2>vue-crono ⏰</h2>
<div class="segment">
<h3>The current time is {{ currentTime }}</h3>
<p>updated every 5 seconds by <pre>cron: { time: 5000, method: 'load'}</pre></p>
<button v-if="cronRunning" v-on:click="stopTimer">Stop Timer</button>
<button v-if="!cronRunning" v-on:click="startTimer">Start Timer</button>
<!-- <button v-on:click="adjustTimer(10)">Change interval to 10 second updates</button>
<button v-on:click="adjustTimer(5)">Change interval to 5 second updates</button>-->
</div>
<br/>
<br/>
<div class="segment">
<h3>Clean Time Display</h3>
<p>Show users how long ago something occurred in a concise manner by binding a Date object to <pre><clean-time></clean-time></pre> (times are set to update every minute)</p>
<div class="time-table">
🕒<clean-time v-bind:time="fiveMinutesAgo" v-bind:round="1"></clean-time> Minutes ago (capped at 55 minutes)
<br/>
🕒<clean-time v-bind:time="fiveHoursAgo"></clean-time> Hours ago (capped at 8 hours)
<br/>
🕒<clean-time v-bind:time="yesterday"></clean-time> Approximately one Day ago
<br/>
🕒<clean-time v-bind:time="tenDaysAgo"></clean-time> Days ago (displays actual date in user's locale format)
</div>
<p>You can also change the display strings</p>
<div class="time-table">
🕒<clean-time v-bind:time="minuteAgo" v-bind:round="1" ref="smallestTime" v-bind:locale-map="{ en: {
minute: 'just now',
minutes: '${time} minutes ago',
hour: '${time} hour ago',
hours: '${time} hours ago',
day: '${time} day ago',
days: '${time} days ago'
} }"></clean-time> 1 minute ago or less
<br/>
🕒<clean-time v-bind:time="yesterday" v-bind:round="1" v-bind:locale-map="{ en: {
minute: 'just now',
minutes: '${time} minutes ago',
hour: '${time} hour ago',
hours: '${time} hours ago',
day: 'yesterday',
days: '${time} days ago'
} }"></clean-time> Approximately one Day ago
</div>
</div>
</div>
</template>
<script>
import cleanTime from '../cleanTime.vue';
export default{
data(){
const minuteAgo = new Date();
const fiveMinutesAgo = new Date();
fiveMinutesAgo.setMinutes(new Date().getMinutes() - 4);
const fiveHoursAgo = new Date();
fiveHoursAgo.setHours(new Date().getHours() - 5);
const yesterday = new Date();
yesterday.setHours(new Date().getHours() - 24);
const tenDaysAgo = new Date();
tenDaysAgo.setHours(new Date().getHours() - 24 * 10);
return {
currentTime: undefined,
cronRunning: true,
minuteAgo,
fiveMinutesAgo,
fiveHoursAgo,
yesterday,
tenDaysAgo
};
},
components: {
cleanTime
},
methods: {
load(){
this.currentTime = (new Date().toLocaleTimeString());
},
stopTimer(){
this.$cron.stop('load');
this.cronRunning = false;
},
startTimer(){
this.$cron.start('load');
this.cronRunning = true;
},
adjustTimer(time){
this.$cron.time('load', time * 1000);
}
},
mounted(){
this.load();
},
cron: {
time: 5000,
method: 'load'
}
};
</script>
<style>
body{
font-family:Helvetica
}
h2,
h3{
color:rgba(0, 0, 0, 0.85);
}
h3{
font-family:"Times New Roman";
font-size:5rem;
margin-top: .5em;
margin-bottom: .5em;
}
div{
text-align:center;
}
.segment {
box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15);
margin: .1rem .1em;
padding: .4rem;
max-width:65%;
margin-left:auto;
margin-right:auto;
}
.time-table{
text-align:left;
margin-left:auto;
margin-right:auto;
display:inline-block;
}
.vue-crono-time{
font-weight:bold;
}
</style>