Permalink
Browse files

Fix: User `date` on HTML formatter

Close #1386
  • Loading branch information...
sarvaje authored and alrra committed Oct 8, 2018
1 parent 1f4b104 commit c6f9203f9443420d17ea508e7d8337604b4d48a6
@@ -278,6 +278,30 @@
mql.addListener(validateMediaQuery);
};
var pad = function(time) {
return time < 10 ? `0${time}` : time;
};
var updateDate = function () {
var dateElement = document.getElementById('scan-date');
if (!dateElement) {
return;
}
var isoDateString = dateElement.getAttribute('data-date');
if (!isoDateString) {
return;
}
var isoDate = new Date(isoDateString);
dateElement.textContent = isoDate.getFullYear() + '-' + pad(isoDate.getMonth() + 1) + '-' + pad(isoDate.getDate()) + ' ' + pad(isoDate.getHours()) + ':' + pad(isoDate.getMinutes());
};
updateDate();
if (categoriesListElement) {
registerToggleExpandListener();
registerMediaQuery();
@@ -191,7 +191,7 @@ export default class AnalysisResult {
/** Scan time. */
public scanTime: string;
/** When the scan was started (started in the online scanner). */
public timeStamp: string;
public date: string;
/** webhint version. */
public version?: string;
/** Link to the result (online scanner). */
@@ -221,7 +221,7 @@ export default class AnalysisResult {
this.isFinish = this.status === 'finished' || this.status === 'error';
this.scanTime = this.parseScanTime(options.scanTime || 0);
this.timeStamp = this.parseTimeStamp(options.timeStamp!);
this.date = options.date!;
this.version = options.version;
this.permalink = '';
this.id = '';
@@ -257,14 +257,6 @@ export default class AnalysisResult {
return time;
}
/**
* Return the string of a time stamp.
* @param timeStamp Time in milliseconds.
*/
private parseTimeStamp(timeStamp: number): string {
return moment(timeStamp).format('YYYY-MM-DD H:mm');
}
/**
* Return a category given a name.
* @param name Category name.
@@ -28,13 +28,13 @@
</div>
<% } else { %>
<div class="scan-overview--time-stamp">
<p class="scan-overview__subheader">Date: <span class="overview--time-stamp__time-stamp"><%= result.timeStamp %></span></p>
<p class="scan-overview__subheader">Date: <span id="scan-date" class="overview--time-stamp__time-stamp" data-date="<%= result.date %>"><%= result.date %></span></p>
</div>
<% } %>
</div>
<% if (result.permalink) { %>
<div class="scan-overview--time-stamp">
<p class="scan-overview__subheader">time stamp: <span class="overview--time-stamp__time-stamp"><%= result.timeStamp %></span></p>
<p class="scan-overview__subheader">Date: <span id="scan-date" class="overview--time-stamp__time-stamp" data-date="<%= result.date %>"><%= result.date %></span></p>
</div>
<% } %>
</div>
@@ -357,12 +357,12 @@ export default async (actions: CLIOptions): Promise<boolean> => {
});
};
const print = async (reports: Array<Problem>, target: string, scanTime: number, timeStamp: number): Promise<void> => {
const print = async (reports: Array<Problem>, target: string, scanTime: number, date: string): Promise<void> => {
const formatterOptions: FormatterOptions = {
config: userConfig || undefined,
date,
resources,
scanTime,
timeStamp,
version: loadHintPackage().version
};
@@ -388,7 +388,7 @@ export default async (actions: CLIOptions): Promise<boolean> => {
endSpinner(exitCode ? 'fail' : 'succeed');
await askForTelemetryConfirmation(config);
await print(results, target.href, scanEnd - scanStart, scanStart);
await print(results, target.href, scanEnd - scanStart, new Date(scanStart).toISOString());
} catch (e) {
exitCode = 1;
endSpinner('fail');
@@ -8,7 +8,8 @@ export type FormatterOptions = {
resources?: HintResources;
scanTime?: number;
status?: string;
timeStamp?: number;
/** Start time (queued in online scanner) ISO string */
date?: string;
version?: string;
};

0 comments on commit c6f9203

Please sign in to comment.