Fossil SCM
/chat: added client-local day-of-week to the message time strings. Y-M-D seems awful noisy, per chat room consensus, but we also have code for that if we decide otherwise. A couple code-adjacent internal cleanups.
Commit
65be323110e9b1cb03aa8ce73b817352881142eaf7862b68948ef1200a1a9cc2
Parent
17af40efffe0766…
1 file changed
+33
-18
+33
-18
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -584,14 +584,39 @@ | ||
| 584 | 584 | this.e.tab.setAttribute('role', 'button'); |
| 585 | 585 | if(arguments.length){ |
| 586 | 586 | this.setMessage(arguments[0]); |
| 587 | 587 | } |
| 588 | 588 | }; |
| 589 | + /* Left-zero-pad a number to at least 2 digits */ | |
| 590 | + const pad2 = (x)=>(''+x).length>1 ? x : '0'+x; | |
| 591 | + const dowMap = { | |
| 592 | + /* Map of Date.getDay() values to weekday names. */ | |
| 593 | + 0: "Sunday", 1: "Monday", 2: "Tuesday", | |
| 594 | + 3: "Wednesday", 4: "Thursday", 5: "Friday", | |
| 595 | + 6: "Saturday" | |
| 596 | + }; | |
| 597 | + /* Given a Date, returns the timestamp string used in the | |
| 598 | + "tab" part of message widgets. */ | |
| 589 | 599 | const theTime = function(d){ |
| 590 | - return [d.getHours(),":", | |
| 591 | - (d.getMinutes()+100).toString().slice(1,3) | |
| 592 | - ].join(''); | |
| 600 | + return [ | |
| 601 | + //d.getFullYear(),'-',pad2(d.getMonth()+1/*sigh*/), | |
| 602 | + //'-',pad2(d.getDate()), ' ', | |
| 603 | + d.getHours(),":", | |
| 604 | + (d.getMinutes()+100).toString().slice(1,3), | |
| 605 | + ' ', dowMap[d.getDay()] | |
| 606 | + ].join(''); | |
| 607 | + }; | |
| 608 | + /** Returns the local time string of Date object d, defaulting | |
| 609 | + to the current time. */ | |
| 610 | + const localTimeString = function ff(d){ | |
| 611 | + d || (d = new Date()); | |
| 612 | + return [ | |
| 613 | + d.getFullYear(),'-',pad2(d.getMonth()+1/*sigh*/), | |
| 614 | + '-',pad2(d.getDate()), | |
| 615 | + ' ',pad2(d.getHours()),':',pad2(d.getMinutes()), | |
| 616 | + ':',pad2(d.getSeconds()) | |
| 617 | + ].join(''); | |
| 593 | 618 | }; |
| 594 | 619 | cf.prototype = { |
| 595 | 620 | setLabel: function(label){ |
| 596 | 621 | return this; |
| 597 | 622 | }, |
| @@ -696,10 +721,15 @@ | ||
| 696 | 721 | D.append(D.span(), localTime8601( |
| 697 | 722 | new Date(eMsg.dataset.lmtime) |
| 698 | 723 | ).replace('T',' ')," ",xfrom," time")); |
| 699 | 724 | } |
| 700 | 725 | }else{ |
| 726 | + /* This might not be necessary any more: it was | |
| 727 | + initially caused by Safari being stricter than | |
| 728 | + other browsers on its time string input, and that | |
| 729 | + has since been resolved by emiting a stricter | |
| 730 | + format. */ | |
| 701 | 731 | // Date doesn't work, so dumb it down... |
| 702 | 732 | D.append(this.e, D.append(D.span(), eMsg.dataset.timestamp," zulu")); |
| 703 | 733 | } |
| 704 | 734 | const toolbar = D.addClass(D.div(), 'toolbar'); |
| 705 | 735 | D.append(this.e, toolbar); |
| @@ -891,25 +921,10 @@ | ||
| 891 | 921 | e.preventDefault(); |
| 892 | 922 | Chat.submitMessage(); |
| 893 | 923 | return false; |
| 894 | 924 | }); |
| 895 | 925 | |
| 896 | - /* Returns a new TEXT node with the given text content. */ | |
| 897 | - /** Returns the local time string of Date object d, defaulting | |
| 898 | - to the current time. */ | |
| 899 | - const localTimeString = function ff(d){ | |
| 900 | - if(!ff.pad){ | |
| 901 | - ff.pad = (x)=>(''+x).length>1 ? x : '0'+x; | |
| 902 | - } | |
| 903 | - d || (d = new Date()); | |
| 904 | - return [ | |
| 905 | - d.getFullYear(),'-',ff.pad(d.getMonth()+1/*sigh*/), | |
| 906 | - '-',ff.pad(d.getDate()), | |
| 907 | - ' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()), | |
| 908 | - ':',ff.pad(d.getSeconds()) | |
| 909 | - ].join(''); | |
| 910 | - }; | |
| 911 | 926 | /* Returns an almost-ISO8601 form of Date object d. */ |
| 912 | 927 | const iso8601ish = function(d){ |
| 913 | 928 | return d.toISOString() |
| 914 | 929 | .replace('T',' ').replace(/\.\d+/,'').replace('Z', ' zulu'); |
| 915 | 930 | }; |
| 916 | 931 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -584,14 +584,39 @@ | |
| 584 | this.e.tab.setAttribute('role', 'button'); |
| 585 | if(arguments.length){ |
| 586 | this.setMessage(arguments[0]); |
| 587 | } |
| 588 | }; |
| 589 | const theTime = function(d){ |
| 590 | return [d.getHours(),":", |
| 591 | (d.getMinutes()+100).toString().slice(1,3) |
| 592 | ].join(''); |
| 593 | }; |
| 594 | cf.prototype = { |
| 595 | setLabel: function(label){ |
| 596 | return this; |
| 597 | }, |
| @@ -696,10 +721,15 @@ | |
| 696 | D.append(D.span(), localTime8601( |
| 697 | new Date(eMsg.dataset.lmtime) |
| 698 | ).replace('T',' ')," ",xfrom," time")); |
| 699 | } |
| 700 | }else{ |
| 701 | // Date doesn't work, so dumb it down... |
| 702 | D.append(this.e, D.append(D.span(), eMsg.dataset.timestamp," zulu")); |
| 703 | } |
| 704 | const toolbar = D.addClass(D.div(), 'toolbar'); |
| 705 | D.append(this.e, toolbar); |
| @@ -891,25 +921,10 @@ | |
| 891 | e.preventDefault(); |
| 892 | Chat.submitMessage(); |
| 893 | return false; |
| 894 | }); |
| 895 | |
| 896 | /* Returns a new TEXT node with the given text content. */ |
| 897 | /** Returns the local time string of Date object d, defaulting |
| 898 | to the current time. */ |
| 899 | const localTimeString = function ff(d){ |
| 900 | if(!ff.pad){ |
| 901 | ff.pad = (x)=>(''+x).length>1 ? x : '0'+x; |
| 902 | } |
| 903 | d || (d = new Date()); |
| 904 | return [ |
| 905 | d.getFullYear(),'-',ff.pad(d.getMonth()+1/*sigh*/), |
| 906 | '-',ff.pad(d.getDate()), |
| 907 | ' ',ff.pad(d.getHours()),':',ff.pad(d.getMinutes()), |
| 908 | ':',ff.pad(d.getSeconds()) |
| 909 | ].join(''); |
| 910 | }; |
| 911 | /* Returns an almost-ISO8601 form of Date object d. */ |
| 912 | const iso8601ish = function(d){ |
| 913 | return d.toISOString() |
| 914 | .replace('T',' ').replace(/\.\d+/,'').replace('Z', ' zulu'); |
| 915 | }; |
| 916 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -584,14 +584,39 @@ | |
| 584 | this.e.tab.setAttribute('role', 'button'); |
| 585 | if(arguments.length){ |
| 586 | this.setMessage(arguments[0]); |
| 587 | } |
| 588 | }; |
| 589 | /* Left-zero-pad a number to at least 2 digits */ |
| 590 | const pad2 = (x)=>(''+x).length>1 ? x : '0'+x; |
| 591 | const dowMap = { |
| 592 | /* Map of Date.getDay() values to weekday names. */ |
| 593 | 0: "Sunday", 1: "Monday", 2: "Tuesday", |
| 594 | 3: "Wednesday", 4: "Thursday", 5: "Friday", |
| 595 | 6: "Saturday" |
| 596 | }; |
| 597 | /* Given a Date, returns the timestamp string used in the |
| 598 | "tab" part of message widgets. */ |
| 599 | const theTime = function(d){ |
| 600 | return [ |
| 601 | //d.getFullYear(),'-',pad2(d.getMonth()+1/*sigh*/), |
| 602 | //'-',pad2(d.getDate()), ' ', |
| 603 | d.getHours(),":", |
| 604 | (d.getMinutes()+100).toString().slice(1,3), |
| 605 | ' ', dowMap[d.getDay()] |
| 606 | ].join(''); |
| 607 | }; |
| 608 | /** Returns the local time string of Date object d, defaulting |
| 609 | to the current time. */ |
| 610 | const localTimeString = function ff(d){ |
| 611 | d || (d = new Date()); |
| 612 | return [ |
| 613 | d.getFullYear(),'-',pad2(d.getMonth()+1/*sigh*/), |
| 614 | '-',pad2(d.getDate()), |
| 615 | ' ',pad2(d.getHours()),':',pad2(d.getMinutes()), |
| 616 | ':',pad2(d.getSeconds()) |
| 617 | ].join(''); |
| 618 | }; |
| 619 | cf.prototype = { |
| 620 | setLabel: function(label){ |
| 621 | return this; |
| 622 | }, |
| @@ -696,10 +721,15 @@ | |
| 721 | D.append(D.span(), localTime8601( |
| 722 | new Date(eMsg.dataset.lmtime) |
| 723 | ).replace('T',' ')," ",xfrom," time")); |
| 724 | } |
| 725 | }else{ |
| 726 | /* This might not be necessary any more: it was |
| 727 | initially caused by Safari being stricter than |
| 728 | other browsers on its time string input, and that |
| 729 | has since been resolved by emiting a stricter |
| 730 | format. */ |
| 731 | // Date doesn't work, so dumb it down... |
| 732 | D.append(this.e, D.append(D.span(), eMsg.dataset.timestamp," zulu")); |
| 733 | } |
| 734 | const toolbar = D.addClass(D.div(), 'toolbar'); |
| 735 | D.append(this.e, toolbar); |
| @@ -891,25 +921,10 @@ | |
| 921 | e.preventDefault(); |
| 922 | Chat.submitMessage(); |
| 923 | return false; |
| 924 | }); |
| 925 | |
| 926 | /* Returns an almost-ISO8601 form of Date object d. */ |
| 927 | const iso8601ish = function(d){ |
| 928 | return d.toISOString() |
| 929 | .replace('T',' ').replace(/\.\d+/,'').replace('Z', ' zulu'); |
| 930 | }; |
| 931 |