superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Use 3 letters month prefix in default date format (#4693)
Date Thu, 29 Mar 2018 21:41:25 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 2967868  Use 3 letters month prefix in default date format (#4693)
2967868 is described below

commit 29678680ee56a1be968a633e9c5186fafec56875
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Thu Mar 29 14:41:22 2018 -0700

    Use 3 letters month prefix in default date format (#4693)
---
 superset/assets/javascripts/modules/dates.js          | 19 +++++++++++++------
 .../assets/spec/javascripts/modules/dates_spec.js     | 13 +++++++++++++
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/superset/assets/javascripts/modules/dates.js b/superset/assets/javascripts/modules/dates.js
index c1bf47d..91fde25 100644
--- a/superset/assets/javascripts/modules/dates.js
+++ b/superset/assets/javascripts/modules/dates.js
@@ -42,25 +42,32 @@ export const tickMultiFormat = d3.time.format.multi([
   ],
   // If there are hours that are multiples of 3, show date and AM/PM
   [
-    '%a %b %d',
+    '%a %b %e',
     function (d) {
-      return d.getDate() !== 1;
+      return d.getDate() >= 10;
     },
   ],
-  // If not the first of the month, do "month day, year."
+  // If not the first of the month: "Tue Mar 2"
   [
-    '%B %Y',
+    '%a %b%e',
+    function (d) {
+      return d.getDate() > 1;
+    },
+  ],
+  // If >= 10th of the month, compensate for padding : "Sun Mar 15"
+  [
+    '%b %Y',
     function (d) {
       return d.getMonth() !== 0 && d.getDate() === 1;
     },
   ],
-  // If the first of the month, do "month day, year."
+  // If the first of the month: 'Mar 2020'
   [
     '%Y',
     function () {
       return true;
     },
-  ],  // fall back on month, year
+  ],  // fall back on just year: '2020'
 ]);
 export const formatDate = function (dttm) {
   const d = UTC(new Date(dttm));
diff --git a/superset/assets/spec/javascripts/modules/dates_spec.js b/superset/assets/spec/javascripts/modules/dates_spec.js
index b073921..9eecaf1 100644
--- a/superset/assets/spec/javascripts/modules/dates_spec.js
+++ b/superset/assets/spec/javascripts/modules/dates_spec.js
@@ -20,6 +20,19 @@ describe('formatDate', () => {
   it('is a function', () => {
     assert.isFunction(formatDate);
   });
+
+  it('shows only year when 1st day of the year', () => {
+    expect(formatDate(new Date('2020-01-01'))).to.equal('2020');
+  });
+
+  it('shows month and year when 1st of month', () => {
+    expect(formatDate(new Date('2020-03-01'))).to.equal('Mar 2020');
+  });
+
+  it('shows weekday when any day of the month', () => {
+    expect(formatDate(new Date('2020-03-03'))).to.equal('Tue Mar 3');
+    expect(formatDate(new Date('2020-03-15'))).to.equal('Sun Mar 15');
+  });
 });
 
 describe('fDuration', () => {

-- 
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.

Mime
View raw message