Skip to content

Commit 09d416f

Browse files
committed
Remove day from dates
1 parent 962e3a3 commit 09d416f

6 files changed

Lines changed: 49 additions & 8 deletions

File tree

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/techreport/tableLinked.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class TableLinked {
8181
}
8282

8383
if(timestamp) {
84-
timestamp.textContent = this.dataArray[1]?.[0]?.date;
84+
timestamp.textContent = UIUtils.printMonthYear(this.dataArray[1]?.[0]?.date);
8585
}
8686

8787
this.dataArray.forEach(technology => {

src/js/techreport/timeseries.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Timeseries {
131131
container.innerHTML = '';
132132

133133
/* Update the date to the most recent timestamp in the dataset */
134-
viz.querySelector('[data-slot="timestamp"]').innerHTML = sorted?.[0]?.date;
134+
viz.querySelector('[data-slot="timestamp"]').innerHTML = UIUtils.printMonthYear(sorted?.[0]?.date);
135135

136136
/* For each of the breakdowns, add a component with the latest data */
137137
config.series.values.forEach(breakdown => {
@@ -239,7 +239,7 @@ class Timeseries {
239239
value.classList.add('undefined');
240240
value.textContent = 'No data';
241241
}
242-
timestamp.textContent = latest.date;
242+
timestamp.textContent = UIUtils.printMonthYear(latest.date);
243243
const techColor = UIUtils.getAppColor(app, this.pageFilters.app, this.pageConfig.colors);
244244
const fallback = this.pageConfig.colors.app[index];
245245
card.style.setProperty('--breakdown-color', techColor || fallback);
@@ -314,7 +314,7 @@ class Timeseries {
314314
const wrapper = document.createElement('div');
315315
wrapper.className = 'tooltip-wrapper';
316316

317-
const d = Highcharts.dateFormat('%b %e, %Y', this.x);
317+
const d = Highcharts.dateFormat('%b %Y', this.x);
318318

319319
const dateEl = document.createElement('p');
320320
dateEl.innerHTML = d;

src/js/techreport/utils/ui.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,23 @@ function capitalizeFirstLetter(theString) {
6161
return theString && typeof theString === 'string' ? theString.charAt(0)?.toUpperCase() + theString.slice(1) : theString;
6262
}
6363

64+
function printMonthYear(theDate) {
65+
if (!theDate || theDate.length != 10) return;
66+
67+
const [year, month, day] = theDate.split('-');
68+
const date = new Date(year, month - 1);
69+
const formattedDate = date.toLocaleString('default', {
70+
month: 'long',
71+
year: 'numeric'
72+
});
73+
74+
return formattedDate;
75+
}
76+
6477
export const UIUtils = {
6578
getAppColor,
6679
updateReportComponents,
6780
getChangeStatus,
6881
capitalizeFirstLetter,
82+
printMonthYear,
6983
}

src/js/timeseries.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,14 @@ function drawChart(options, series) {
317317
}
318318

319319
const changelog = flags[this.x];
320-
const tooltip = `<p style="font-size: smaller; text-align: center;">${Highcharts.dateFormat('%b %e, %Y', this.x)}</p>`;
320+
321+
// Drop the 1st day from dates as data is for month, rather than
322+
// specific date. However, include the non-01 dates from when we
323+
// used to run an early (01) and late (15 typically) crawl.
324+
const formattedDate = Highcharts.dateFormat('%e', this.x) === ' 1' ?
325+
Highcharts.dateFormat('%b %Y', this.x) :
326+
Highcharts.dateFormat('%b %e, %Y', this.x);
327+
const tooltip = `<p style="font-size: smaller; text-align: center;">${formattedDate}</p>`;
321328

322329
// Handle changelog tooltips first.
323330
if (!this.points) {
@@ -390,7 +397,8 @@ function drawChart(options, series) {
390397
}, {
391398
type: 'all',
392399
text: 'All'
393-
}]
400+
}],
401+
inputDateFormat: '%b %Y',
394402
},
395403
xAxis: {
396404
type: 'datetime',

src/js/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ const prettyDateFormatter = new Intl.DateTimeFormat(undefined, {
77
timeZone: 'UTC'
88
});
99

10+
const prettyShortDateFormatter = new Intl.DateTimeFormat(undefined, {
11+
month: 'short',
12+
year: 'numeric',
13+
timeZone: 'UTC'
14+
});
15+
1016
export const prettyDate = YYYY_MM_DD => {
1117
const [YYYY, MM, DD] = YYYY_MM_DD.split('_');
1218
const d = new Date(Date.UTC(YYYY, MM - 1, DD));
13-
return getFullDate(d);
19+
const formattedDate = DD === '01' ?
20+
prettyShortDateFormatter.format(d) :
21+
prettyDateFormatter.format(d);
22+
return formattedDate;
1423
};
1524

1625
export const getFullDate = d => {

0 commit comments

Comments
 (0)