Browse Source

Show full date in title text

Danilo Bargen 7 years ago
parent
commit
4c545f0697
3 changed files with 12 additions and 5 deletions
  1. 1 1
      src/directives/message_date.ts
  2. 4 4
      src/filters.ts
  3. 7 0
      tests/filters.js

+ 1 - 1
src/directives/message_date.ts

@@ -23,7 +23,7 @@ export default [
                 message: '=eeeMessage',
             },
             template: `
-                <span>{{ message.date | unixToTimestring }}</span>
+                <span title="{{ message.date | unixToTimestring:true }}">{{ message.date | unixToTimestring }}</span>
             `,
         };
     },

+ 4 - 4
src/filters.ts

@@ -374,21 +374,21 @@ angular.module('3ema.filters', [])
             && date1.getDate() === date2.getDate();
     }
 
-    return (timestamp: number) => {
+    return (timestamp: number, forceFull: boolean = false) => {
         const date = new Date(timestamp * 1000);
 
         const now = new Date();
-        if (isSameDay(date, now)) {
+        if (!forceFull && isSameDay(date, now)) {
             return formatTime(date);
         }
 
         const yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
-        if (isSameDay(date, yesterday)) {
+        if (!forceFull && isSameDay(date, yesterday)) {
             return $translate.instant('date.YESTERDAY') + ', ' + formatTime(date);
         }
 
         let year = '';
-        if (date.getFullYear() !== now.getFullYear()) {
+        if (forceFull || date.getFullYear() !== now.getFullYear()) {
             year = ' ' + date.getFullYear();
         }
         return date.getDate() + '. '

+ 7 - 0
tests/filters.js

@@ -261,6 +261,13 @@ describe('Filters', function() {
             ]);
         });
 
+        it('shows full date with forceFull flag', () => {
+            const d = new Date();
+            const formatted = $filter('unixToTimestring')(d.getTime() / 1000, true);
+            expect(formatted.length > 10).toBe(true);
+            expect(formatted).toContain(d.getFullYear().toString());
+        });
+
         it('shows "yesterday" for yesterday', () => {
             const d1 = new Date();
             const ts = d1.getTime();