Skip to content

Commit f270d86

Browse files
tunethewebgithub-advanced-security[bot]max-ostapenko
authored
Remove day from dates (#1175)
* Remove day from dates * Potential fix for code scanning alert no. 72: Unused variable, import, function or class Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Update src/js/timeseries.js Co-authored-by: Max Ostapenko <1611259+max-ostapenko@users.noreply.github.com> * Fixes * Fix mock dates --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Max Ostapenko <1611259+max-ostapenko@users.noreply.github.com>
1 parent 7791fa0 commit f270d86

File tree

7 files changed

+54
-12
lines changed

7 files changed

+54
-12
lines changed

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.

server/dates.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ def mock_get_dates(start_year, end_year, today, month_delta=0):
3838
current_month_in_year = "0{}".format(current_month_in_year)
3939

4040
months.append("{}_{}_01".format(year, current_month_in_year))
41-
if year == end_year and current_month_in_year == month_delta and today < 15:
42-
continue
43-
months.append("{}_{}_15".format(year, current_month_in_year))
41+
if year < 2019:
42+
months.append("{}_{}_15".format(year, current_month_in_year))
4443

4544
if month % 12 == 0:
4645
year = year + 1

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] = 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+
// Use short format (month + year) for dates from 2019 onwards when
322+
// we switched to monthly crawls. Show full date for older data that
323+
// may have had mid-month crawls.
324+
const formattedDate = this.x >= Date.UTC(2019, 0, 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: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@ 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('_');
12-
const d = new Date(Date.UTC(YYYY, MM - 1, DD));
13-
return getFullDate(d);
18+
if (YYYY > '2018') {
19+
const d = new Date(Date.UTC(YYYY, MM - 1));
20+
return prettyShortDateFormatter.format(d);
21+
} else {
22+
const d = new Date(Date.UTC(YYYY, MM - 1, DD));
23+
return prettyDateFormatter.format(d);
24+
}
1425
};
1526

1627
export const getFullDate = d => {

0 commit comments

Comments
 (0)