瀏覽代碼

Fix timeAgo and notifications

Daniel Supernault 3 月之前
父節點
當前提交
27fa798208

+ 1 - 29
resources/assets/components/partials/timeline/Notification.vue

@@ -142,35 +142,7 @@
 			},
 			},
 
 
             timeAgo(ts) {
             timeAgo(ts) {
-                let date = new Date(ts);
-                let now = new Date();
-                let seconds = Math.floor((now - date) / 1000);
-                let interval = Math.floor(seconds / 31536000);
-                if (interval >= 1) {
-                    return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'year');
-                }
-                interval = Math.floor(seconds / 2592000);
-                if (interval >= 1) {
-                    return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'month');
-                }
-                interval = Math.floor(seconds / 604800);
-                if (interval >= 1) {
-                    return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'week');
-                }
-                interval = Math.floor(seconds / 86400);
-                if (interval >= 1) {
-                    return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'day');
-                }
-                interval = Math.floor(seconds / 3600);
-                if (interval >= 1) {
-                    return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'hour');
-                }
-                interval = Math.floor(seconds / 60);
-                if (interval >= 1) {
-                    return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-interval, 'minute');
-                }
-                return new Intl.RelativeTimeFormat(this.$i18n.locale, { numeric: 'auto' }).format(-seconds, 'second');
-
+                return App.util.format.timeAgo(ts);
 			},
 			},
 
 
 			mentionUrl(status) {
 			mentionUrl(status) {

+ 1 - 1
resources/assets/components/sections/Notifications.vue

@@ -151,7 +151,7 @@
 										</p>
 										</p>
 									</div>
 									</div>
 								</div>
 								</div>
-								<div class="small text-muted font-weight-bold"  style="font-size: 0.575em;"  st :title="n.created_at">{{timeAgo(n.created_at)}}</div>
+								<div class="small text-muted font-weight-bold"  style="font-size: 12px;" :title="n.created_at">{{timeAgo(n.created_at)}}</div>
 							</div>
 							</div>
 						</div>
 						</div>
 
 

+ 23 - 19
resources/assets/js/app.js

@@ -96,36 +96,40 @@ window.App.util = {
 			}
 			}
 			return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count);
 			return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count);
 		}),
 		}),
-		timeAgo: (function(ts) {
-            let date = new Date(ts);
-            let now = new Date();
-            let seconds = Math.floor((now - date) / 1000);
-            let interval = Math.floor(seconds / 31536000);
-            if (interval >= 1) {
-                return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'year');
-            }
-            interval = Math.floor(seconds / 2592000);
+        timeAgo: (function(ts) {
+            const date = new Date(ts);
+            const now = new Date();
+
+            const seconds = Math.floor((now - date) / 1000);
+
+            const secondsInYear = 60 * 60 * 24 * 365.25;
+            let interval = Math.floor(seconds / secondsInYear);
             if (interval >= 1) {
             if (interval >= 1) {
-                return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'month');
+                return interval + "y";
             }
             }
-            interval = Math.floor(seconds / 604800);
+
+            interval = Math.floor(seconds / (60 * 60 * 24 * 7));
             if (interval >= 1) {
             if (interval >= 1) {
-                return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'week');
+                return interval + "w";
             }
             }
-            interval = Math.floor(seconds / 86400);
+
+            interval = Math.floor(seconds / (60 * 60 * 24));
             if (interval >= 1) {
             if (interval >= 1) {
-                return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'day');
+                return interval + "d";
             }
             }
-            interval = Math.floor(seconds / 3600);
+
+            interval = Math.floor(seconds / (60 * 60));
             if (interval >= 1) {
             if (interval >= 1) {
-                return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'hour');
+                return interval + "h";
             }
             }
+
             interval = Math.floor(seconds / 60);
             interval = Math.floor(seconds / 60);
             if (interval >= 1) {
             if (interval >= 1) {
-                return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-interval, 'minute');
+                return interval + "m";
             }
             }
-            return new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' }).format(-seconds, 'second');
-		}),
+
+            return Math.floor(seconds) + "s";
+        }),
 		timeAhead: (function(ts, short = true) {
 		timeAhead: (function(ts, short = true) {
 			let date = Date.parse(ts);
 			let date = Date.parse(ts);
 			let diff = date - Date.parse(new Date());
 			let diff = date - Date.parse(new Date());

文件差異過大導致無法顯示
+ 484 - 484
resources/assets/js/spa.js


部分文件因文件數量過多而無法顯示