Răsfoiți Sursa

Expand _strftime: add %a, %I, %-I, %p

ZiB 4 luni în urmă
părinte
comite
ee8f66cb00
1 a modificat fișierele cu 8 adăugiri și 1 ștergeri
  1. 8 1
      room_cal/vue/calendar.html

+ 8 - 1
room_cal/vue/calendar.html

@@ -1552,6 +1552,9 @@ createApp({
       const pad = n => String(n).padStart(2, '0');
       const MONTHS_LONG  = ['January','February','March','April','May','June','July','August','September','October','November','December'];
       const MONTHS_SHORT = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
+      const DAYS_SHORT   = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
+      const h24 = date.getHours();
+      const h12 = h24 % 12 || 12;
       return fmt
         .replace(/%-d/g, String(date.getDate()))
         .replace(/%d/g,  pad(date.getDate()))
@@ -1559,8 +1562,12 @@ createApp({
         .replace(/%m/g,  pad(date.getMonth() + 1))
         .replace(/%B/g,  MONTHS_LONG[date.getMonth()])
         .replace(/%b/g,  MONTHS_SHORT[date.getMonth()])
+        .replace(/%a/g,  DAYS_SHORT[date.getDay()])
         .replace(/%Y/g,  String(date.getFullYear()))
-        .replace(/%y/g,  String(date.getFullYear()).slice(-2));
+        .replace(/%y/g,  String(date.getFullYear()).slice(-2))
+        .replace(/%-I/g, String(h12))
+        .replace(/%I/g,  pad(h12))
+        .replace(/%p/g,  h24 < 12 ? 'AM' : 'PM');
     }
 
     function applyTemplate(name) {