From 1200617639db7aac537ba514b8d5fcc0437efd84 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 15 Jul 2020 14:34:57 +0100 Subject: [PATCH 1/5] Migration of activitylog and datetime to ES6 modules --- package.json | 2 ++ src/components/activitylog.js | 29 +++++++++++++++------ src/controllers/dashboard/serveractivity.js | 2 +- src/scripts/datetime.js | 24 +++++++++-------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 51f1ae10d2..81d8b5f950 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "test": [ "src/components/accessSchedule/accessSchedule.js", "src/components/actionSheet/actionSheet.js", + "src/components/activitylog.js", "src/components/alphaPicker/alphaPicker.js", "src/components/autoFocuser.js", "src/components/cardbuilder/cardBuilder.js", @@ -150,6 +151,7 @@ "src/plugins/bookPlayer/plugin.js", "src/plugins/bookPlayer/tableOfContents.js", "src/plugins/photoPlayer/plugin.js", + "src/scripts/datetime.js", "src/scripts/deleteHelper.js", "src/scripts/dfnshelper.js", "src/scripts/dom.js", diff --git a/src/components/activitylog.js b/src/components/activitylog.js index bbb0995063..b51fc6787a 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -1,5 +1,15 @@ -define(['events', 'globalize', 'dom', 'date-fns', 'dfnshelper', 'userSettings', 'serverNotifications', 'connectionManager', 'emby-button', 'listViewStyle'], function (events, globalize, dom, datefns, dfnshelper, userSettings, serverNotifications, connectionManager) { - 'use strict'; +import events from 'events'; +import globalize from 'globalize'; +import dom from 'dom'; +import * as datefns from 'date-fns'; +import dfnshelper from 'dfnshelper'; +import userSettings from 'userSettings'; +import serverNotifications from 'serverNotifications'; +import connectionManager from 'connectionManager'; +import 'emby-button'; +import 'listViewStyle'; + +/*eslint-disable indent */ function getEntryHtml(entry, apiClient) { var html = ''; @@ -125,7 +135,9 @@ define(['events', 'globalize', 'dom', 'date-fns', 'dfnshelper', 'userSettings', }); } - function ActivityLog(options) { +class ActivityLog { + constructor(options) { + console.log(options) this.options = options; var element = options.element; element.classList.add('activityLogListWidget'); @@ -137,8 +149,7 @@ define(['events', 'globalize', 'dom', 'date-fns', 'dfnshelper', 'userSettings', events.on(serverNotifications, 'ActivityLogEntry', onUpdate); apiClient.sendMessage('ActivityLogEntryStart', '0,1500'); } - - ActivityLog.prototype.destroy = function () { + destroy() { var options = this.options; if (options) { @@ -154,7 +165,9 @@ define(['events', 'globalize', 'dom', 'date-fns', 'dfnshelper', 'userSettings', this.items = null; this.options = null; - }; + } +} - return ActivityLog; -}); +export default ActivityLog; + +/*eslint-enable indent */ diff --git a/src/controllers/dashboard/serveractivity.js b/src/controllers/dashboard/serveractivity.js index c48a2903ae..a3ce91592f 100644 --- a/src/controllers/dashboard/serveractivity.js +++ b/src/controllers/dashboard/serveractivity.js @@ -14,7 +14,7 @@ define(['components/activitylog', 'globalize'], function (ActivityLog, globalize view.addEventListener('viewshow', function () { if (!activityLog) { - activityLog = new ActivityLog({ + activityLog = new ActivityLog.default({ serverId: ApiClient.serverId(), element: view.querySelector('.activityItems') }); diff --git a/src/scripts/datetime.js b/src/scripts/datetime.js index 34ff23fe63..6b7aa69996 100644 --- a/src/scripts/datetime.js +++ b/src/scripts/datetime.js @@ -1,7 +1,8 @@ -define(['globalize'], function (globalize) { - 'use strict'; +import globalize from 'globalize'; - function parseISO8601Date(s, toLocal) { +/*eslint-disable indent */ + + export function parseISO8601Date(s, toLocal) { // parenthese matches: // year month day hours minutes seconds @@ -58,7 +59,7 @@ define(['globalize'], function (globalize) { return new Date(ms); } - function getDisplayRunningTime(ticks) { + export function getDisplayRunningTime(ticks) { var ticksPerHour = 36000000000; var ticksPerMinute = 600000000; var ticksPerSecond = 10000000; @@ -118,7 +119,7 @@ define(['globalize'], function (globalize) { return list; } - function toLocaleString(date, options) { + export function toLocaleString(date, options) { if (!date) { throw new Error('date cannot be null'); @@ -138,7 +139,7 @@ define(['globalize'], function (globalize) { return date.toLocaleString(); } - function toLocaleDateString(date, options) { + export function toLocaleDateString(date, options) { if (!date) { throw new Error('date cannot be null'); @@ -172,7 +173,7 @@ define(['globalize'], function (globalize) { return date.toLocaleDateString(); } - function toLocaleTimeString(date, options) { + export function toLocaleTimeString(date, options) { if (!date) { throw new Error('date cannot be null'); @@ -192,7 +193,7 @@ define(['globalize'], function (globalize) { return date.toLocaleTimeString(); } - function getDisplayTime(date) { + export function getDisplayTime(date) { if (!date) { throw new Error('date cannot be null'); @@ -253,7 +254,7 @@ define(['globalize'], function (globalize) { return time; } - function isRelativeDay(date, offsetInDays) { + export function isRelativeDay(date, offsetInDays) { if (!date) { throw new Error('date cannot be null'); @@ -267,7 +268,7 @@ define(['globalize'], function (globalize) { return date.getFullYear() === yesterday.getFullYear() && date.getMonth() === yesterday.getMonth() && date.getDate() === day; } - return { + export default { parseISO8601Date: parseISO8601Date, getDisplayRunningTime: getDisplayRunningTime, toLocaleDateString: toLocaleDateString, @@ -279,4 +280,5 @@ define(['globalize'], function (globalize) { return toLocaleTimeStringSupportsLocales; } }; -}); + +/*eslint-enable indent */ From 45df6ef764bd469abab449d7966ab5136170bfe2 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 15 Jul 2020 14:46:56 +0100 Subject: [PATCH 2/5] Migration of alert to ES6 module --- package.json | 1 + src/components/activitylog.js | 3 +-- src/components/alert.js | 14 +++++++++----- src/components/appRouter.js | 2 +- src/components/multiSelect/multiSelect.js | 2 +- src/components/playback/playbackmanager.js | 2 +- src/controllers/dashboard/encodingsettings.js | 2 +- src/controllers/dashboard/metadatanfo.js | 2 +- src/controllers/itemDetails.js | 2 +- src/plugins/chromecastPlayer/plugin.js | 2 +- src/scripts/serverNotifications.js | 2 +- src/scripts/site.js | 2 +- 12 files changed, 20 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 81d8b5f950..1707f06202 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ "src/components/accessSchedule/accessSchedule.js", "src/components/actionSheet/actionSheet.js", "src/components/activitylog.js", + "src/components/alert.js", "src/components/alphaPicker/alphaPicker.js", "src/components/autoFocuser.js", "src/components/cardbuilder/cardBuilder.js", diff --git a/src/components/activitylog.js b/src/components/activitylog.js index b51fc6787a..75b07a4cc8 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -128,7 +128,7 @@ import 'listViewStyle'; } function showItemOverview(item) { - require(['alert'], function (alert) { + import('alert').then(({default: alert})=> { alert({ text: item.Overview }); @@ -137,7 +137,6 @@ import 'listViewStyle'; class ActivityLog { constructor(options) { - console.log(options) this.options = options; var element = options.element; element.classList.add('activityLogListWidget'); diff --git a/src/components/alert.js b/src/components/alert.js index 97b580f8f6..80bfbc48e8 100644 --- a/src/components/alert.js +++ b/src/components/alert.js @@ -1,12 +1,15 @@ -define(['browser', 'dialog', 'globalize'], function (browser, dialog, globalize) { - 'use strict'; +import browser from 'browser'; +import dialog from 'dialog'; +import globalize from 'globalize'; + +/*eslint-disable indent*/ function replaceAll(originalString, strReplace, strWith) { var reg = new RegExp(strReplace, 'ig'); return originalString.replace(reg, strWith); } - return function (text, title) { + export default function (text, title) { var options; if (typeof text === 'string') { @@ -41,5 +44,6 @@ define(['browser', 'dialog', 'globalize'], function (browser, dialog, globalize) } return Promise.resolve(); - }; -}); + } + +/*eslint-enable indent*/ diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 0861cf7e00..c2bec1769f 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -53,7 +53,7 @@ define(['loading', 'globalize', 'events', 'viewManager', 'skinManager', 'backdro break; case 'ServerUpdateNeeded': require(['alert'], function (alert) { - alert({ + alert.default({ text: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin'), html: globalize.translate('ServerUpdateNeeded', 'https://github.com/jellyfin/jellyfin') }).then(function () { diff --git a/src/components/multiSelect/multiSelect.js b/src/components/multiSelect/multiSelect.js index 05a2b68f42..922a1fcc19 100644 --- a/src/components/multiSelect/multiSelect.js +++ b/src/components/multiSelect/multiSelect.js @@ -338,7 +338,7 @@ define(['browser', 'appStorage', 'apphost', 'loading', 'connectionManager', 'glo if (selection.length < 2) { require(['alert'], function (alert) { - alert({ + alert.default({ text: globalize.translate('PleaseSelectTwoItems') }); }); diff --git a/src/components/playback/playbackmanager.js b/src/components/playback/playbackmanager.js index 73f07a05f2..b74ca5fb3d 100644 --- a/src/components/playback/playbackmanager.js +++ b/src/components/playback/playbackmanager.js @@ -709,7 +709,7 @@ define(['events', 'datetime', 'appSettings', 'itemHelper', 'pluginManager', 'pla function showPlaybackInfoErrorMessage(instance, errorCode, playNextTrack) { require(['alert'], function (alert) { - alert({ + alert.default({ text: globalize.translate('PlaybackError' + errorCode), title: globalize.translate('HeaderPlaybackError') }).then(function () { diff --git a/src/controllers/dashboard/encodingsettings.js b/src/controllers/dashboard/encodingsettings.js index b8cdd66651..098a8d6f68 100644 --- a/src/controllers/dashboard/encodingsettings.js +++ b/src/controllers/dashboard/encodingsettings.js @@ -86,7 +86,7 @@ define(['jQuery', 'loading', 'globalize', 'dom', 'libraryMenu'], function ($, lo if ($('#selectVideoDecoder', form).val()) { require(['alert'], function (alert) { - alert({ + alert.default({ title: globalize.translate('TitleHardwareAcceleration'), text: globalize.translate('HardwareAccelerationWarning') }).then(onDecoderConfirmed); diff --git a/src/controllers/dashboard/metadatanfo.js b/src/controllers/dashboard/metadatanfo.js index a936192618..3ef1a7cbf9 100644 --- a/src/controllers/dashboard/metadatanfo.js +++ b/src/controllers/dashboard/metadatanfo.js @@ -36,7 +36,7 @@ define(['jQuery', 'loading', 'libraryMenu', 'globalize'], function ($, loading, msg.push(globalize.translate('MetadataSettingChangeHelp')); require(['alert'], function (alert) { - alert({ + alert.default({ text: msg.join('

') }); }); diff --git a/src/controllers/itemDetails.js b/src/controllers/itemDetails.js index c9b6b7fc1c..cfaa5ab973 100644 --- a/src/controllers/itemDetails.js +++ b/src/controllers/itemDetails.js @@ -1787,7 +1787,7 @@ define(['loading', 'appRouter', 'layoutManager', 'connectionManager', 'userSetti imageLoader.lazyChildren(collectionItems); collectionItems.querySelector('.btnAddToCollection').addEventListener('click', function () { require(['alert'], function (alert) { - alert({ + alert.default({ text: globalize.translate('AddItemToCollectionHelp'), html: globalize.translate('AddItemToCollectionHelp') + '

' + globalize.translate('ButtonLearnMore') + '' }); diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index b3f75f7a6d..dad95691fc 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -150,7 +150,7 @@ define(['appSettings', 'userSettings', 'playbackManager', 'connectionManager', ' function alertText(text, title) { require(['alert'], function (alert) { - alert({ + alert.default({ text: text, title: title }); diff --git a/src/scripts/serverNotifications.js b/src/scripts/serverNotifications.js index 2553c284f0..8e212ab718 100644 --- a/src/scripts/serverNotifications.js +++ b/src/scripts/serverNotifications.js @@ -15,7 +15,7 @@ define(['connectionManager', 'playbackManager', 'syncPlayManager', 'events', 'in }); } else { require(['alert'], function (alert) { - alert({ title: args.Header, text: args.Text }); + alert.default({ title: args.Header, text: args.Text }); }); } } diff --git a/src/scripts/site.js b/src/scripts/site.js index c3f93d9545..17bff0decb 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -187,7 +187,7 @@ var Dashboard = { } require(['alert'], function (alert) { - alert({ + alert.default({ title: options.title || Globalize.translate('HeaderAlert'), text: options.message }).then(options.callback || function () {}); From 0e374f4ce61921181a48f6c83c0f5ee34bd0a757 Mon Sep 17 00:00:00 2001 From: dkanada Date: Mon, 20 Jul 2020 08:50:30 +0900 Subject: [PATCH 3/5] add space --- src/components/activitylog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/activitylog.js b/src/components/activitylog.js index 75b07a4cc8..271a7e15a8 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -9,7 +9,7 @@ import connectionManager from 'connectionManager'; import 'emby-button'; import 'listViewStyle'; -/*eslint-disable indent */ +/* eslint-disable indent */ function getEntryHtml(entry, apiClient) { var html = ''; From a5e4039db4e0a5a2b75b89de94b1984bd51e024d Mon Sep 17 00:00:00 2001 From: dkanada Date: Mon, 20 Jul 2020 08:51:36 +0900 Subject: [PATCH 4/5] update import statement --- src/components/activitylog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/activitylog.js b/src/components/activitylog.js index 271a7e15a8..abaa98ec25 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -128,7 +128,7 @@ import 'listViewStyle'; } function showItemOverview(item) { - import('alert').then(({default: alert})=> { + import('alert').then(({default: alert}) => { alert({ text: item.Overview }); From b946259777fc4a7623d16aede3b3fccdbb630bc7 Mon Sep 17 00:00:00 2001 From: Cameron Date: Mon, 20 Jul 2020 08:40:13 +0100 Subject: [PATCH 5/5] fix spacing, update variables --- src/components/activitylog.js | 34 +++++++++---------- src/components/alert.js | 10 +++--- src/scripts/datetime.js | 62 +++++++++++++++++------------------ 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/components/activitylog.js b/src/components/activitylog.js index abaa98ec25..2d5a21756f 100644 --- a/src/components/activitylog.js +++ b/src/components/activitylog.js @@ -12,10 +12,10 @@ import 'listViewStyle'; /* eslint-disable indent */ function getEntryHtml(entry, apiClient) { - var html = ''; + let html = ''; html += '
'; - var color = '#00a4dc'; - var icon = 'notifications'; + let color = '#00a4dc'; + let icon = 'notifications'; if ('Error' == entry.Severity || 'Fatal' == entry.Severity || 'Warn' == entry.Severity) { color = '#cc0000'; @@ -66,8 +66,8 @@ import 'listViewStyle'; } limit = limit || parseInt(elem.getAttribute('data-activitylimit') || '7'); - var minDate = new Date(); - var hasUserId = 'false' !== elem.getAttribute('data-useractivity'); + const minDate = new Date(); + const hasUserId = 'false' !== elem.getAttribute('data-useractivity'); if (hasUserId) { minDate.setTime(minDate.getTime() - 24 * 60 * 60 * 1000); // one day back @@ -84,7 +84,7 @@ import 'listViewStyle'; elem.setAttribute('data-activitystartindex', startIndex); elem.setAttribute('data-activitylimit', limit); if (!startIndex) { - var activityContainer = dom.parentWithClass(elem, 'activityContainer'); + const activityContainer = dom.parentWithClass(elem, 'activityContainer'); if (activityContainer) { if (result.Items.length) { @@ -101,7 +101,7 @@ import 'listViewStyle'; } function onActivityLogUpdate(e, apiClient, data) { - var options = this.options; + const options = this.options; if (options && options.serverId === apiClient.serverId()) { reloadData(this, options.element, apiClient); @@ -109,14 +109,14 @@ import 'listViewStyle'; } function onListClick(e) { - var btnEntryInfo = dom.parentWithClass(e.target, 'btnEntryInfo'); + const btnEntryInfo = dom.parentWithClass(e.target, 'btnEntryInfo'); if (btnEntryInfo) { - var id = btnEntryInfo.getAttribute('data-id'); - var items = this.items; + const id = btnEntryInfo.getAttribute('data-id'); + const items = this.items; if (items) { - var item = items.filter(function (i) { + const item = items.filter(function (i) { return i.Id.toString() === id; })[0]; @@ -138,25 +138,25 @@ import 'listViewStyle'; class ActivityLog { constructor(options) { this.options = options; - var element = options.element; + const element = options.element; element.classList.add('activityLogListWidget'); element.addEventListener('click', onListClick.bind(this)); - var apiClient = connectionManager.getApiClient(options.serverId); + const apiClient = connectionManager.getApiClient(options.serverId); reloadData(this, element, apiClient); - var onUpdate = onActivityLogUpdate.bind(this); + const onUpdate = onActivityLogUpdate.bind(this); this.updateFn = onUpdate; events.on(serverNotifications, 'ActivityLogEntry', onUpdate); apiClient.sendMessage('ActivityLogEntryStart', '0,1500'); } destroy() { - var options = this.options; + const options = this.options; if (options) { options.element.classList.remove('activityLogListWidget'); connectionManager.getApiClient(options.serverId).sendMessage('ActivityLogEntryStop', '0,1500'); } - var onUpdate = this.updateFn; + const onUpdate = this.updateFn; if (onUpdate) { events.off(serverNotifications, 'ActivityLogEntry', onUpdate); @@ -169,4 +169,4 @@ class ActivityLog { export default ActivityLog; -/*eslint-enable indent */ +/* eslint-enable indent */ diff --git a/src/components/alert.js b/src/components/alert.js index 80bfbc48e8..5d396e3a62 100644 --- a/src/components/alert.js +++ b/src/components/alert.js @@ -2,16 +2,16 @@ import browser from 'browser'; import dialog from 'dialog'; import globalize from 'globalize'; -/*eslint-disable indent*/ +/* eslint-disable indent */ function replaceAll(originalString, strReplace, strWith) { - var reg = new RegExp(strReplace, 'ig'); + const reg = new RegExp(strReplace, 'ig'); return originalString.replace(reg, strWith); } export default function (text, title) { - var options; + let options; if (typeof text === 'string') { options = { title: title, @@ -24,7 +24,7 @@ import globalize from 'globalize'; if (browser.tv && window.alert) { alert(replaceAll(options.text || '', '
', '\n')); } else { - var items = []; + const items = []; items.push({ name: globalize.translate('ButtonGotIt'), @@ -46,4 +46,4 @@ import globalize from 'globalize'; return Promise.resolve(); } -/*eslint-enable indent*/ +/* eslint-enable indent */ diff --git a/src/scripts/datetime.js b/src/scripts/datetime.js index 6b7aa69996..cab59299ad 100644 --- a/src/scripts/datetime.js +++ b/src/scripts/datetime.js @@ -1,6 +1,6 @@ import globalize from 'globalize'; -/*eslint-disable indent */ +/* eslint-disable indent */ export function parseISO8601Date(s, toLocal) { @@ -8,9 +8,9 @@ import globalize from 'globalize'; // year month day hours minutes seconds // dotmilliseconds // tzstring plusminus hours minutes - var re = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|([+-])(\d{2}):(\d{2}))?/; + const re = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|([+-])(\d{2}):(\d{2}))?/; - var d = s.match(re); + const d = s.match(re); // "2010-12-07T11:00:00.000-09:00" parses to: // ["2010-12-07T11:00:00.000-09:00", "2010", "12", "07", "11", @@ -25,8 +25,8 @@ import globalize from 'globalize'; } // parse strings, leading zeros into proper ints - var a = [1, 2, 3, 4, 5, 6, 10, 11]; - for (var i in a) { + const a = [1, 2, 3, 4, 5, 6, 10, 11]; + for (let i in a) { d[a[i]] = parseInt(d[a[i]], 10); } d[7] = parseFloat(d[7]); @@ -34,7 +34,7 @@ import globalize from 'globalize'; // Date.UTC(year, month[, date[, hrs[, min[, sec[, ms]]]]]) // note that month is 0-11, not 1-12 // see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/UTC - var ms = Date.UTC(d[1], d[2] - 1, d[3], d[4], d[5], d[6]); + let ms = Date.UTC(d[1], d[2] - 1, d[3], d[4], d[5], d[6]); // if there are milliseconds, add them if (d[7] > 0) { @@ -43,7 +43,7 @@ import globalize from 'globalize'; // if there's a timezone, calculate it if (d[8] !== 'Z' && d[10]) { - var offset = d[10] * 60 * 60 * 1000; + let offset = d[10] * 60 * 60 * 1000; if (d[11]) { offset += d[11] * 60 * 1000; } @@ -60,13 +60,13 @@ import globalize from 'globalize'; } export function getDisplayRunningTime(ticks) { - var ticksPerHour = 36000000000; - var ticksPerMinute = 600000000; - var ticksPerSecond = 10000000; + const ticksPerHour = 36000000000; + const ticksPerMinute = 600000000; + const ticksPerSecond = 10000000; - var parts = []; + const parts = []; - var hours = ticks / ticksPerHour; + let hours = ticks / ticksPerHour; hours = Math.floor(hours); if (hours) { @@ -75,7 +75,7 @@ import globalize from 'globalize'; ticks -= (hours * ticksPerHour); - var minutes = ticks / ticksPerMinute; + let minutes = ticks / ticksPerMinute; minutes = Math.floor(minutes); ticks -= (minutes * ticksPerMinute); @@ -85,7 +85,7 @@ import globalize from 'globalize'; } parts.push(minutes); - var seconds = ticks / ticksPerSecond; + let seconds = ticks / ticksPerSecond; seconds = Math.floor(seconds); if (seconds < 10) { @@ -96,7 +96,7 @@ import globalize from 'globalize'; return parts.join(':'); } - var toLocaleTimeStringSupportsLocales = function () { + const toLocaleTimeStringSupportsLocales = function () { try { new Date().toLocaleTimeString('i'); } catch (e) { @@ -107,9 +107,9 @@ import globalize from 'globalize'; function getOptionList(options) { - var list = []; + const list = []; - for (var i in options) { + for (const i in options) { list.push({ name: i, value: options[i] @@ -129,7 +129,7 @@ import globalize from 'globalize'; if (toLocaleTimeStringSupportsLocales) { - var currentLocale = globalize.getCurrentDateTimeLocale(); + const currentLocale = globalize.getCurrentDateTimeLocale(); if (currentLocale) { return date.toLocaleString(currentLocale, options); @@ -149,7 +149,7 @@ import globalize from 'globalize'; if (toLocaleTimeStringSupportsLocales) { - var currentLocale = globalize.getCurrentDateTimeLocale(); + const currentLocale = globalize.getCurrentDateTimeLocale(); if (currentLocale) { return date.toLocaleDateString(currentLocale, options); @@ -157,9 +157,9 @@ import globalize from 'globalize'; } // This is essentially a hard-coded polyfill - var optionList = getOptionList(options); + const optionList = getOptionList(options); if (optionList.length === 1 && optionList[0].name === 'weekday') { - var weekday = []; + const weekday = []; weekday[0] = 'Sun'; weekday[1] = 'Mon'; weekday[2] = 'Tue'; @@ -183,7 +183,7 @@ import globalize from 'globalize'; if (toLocaleTimeStringSupportsLocales) { - var currentLocale = globalize.getCurrentDateTimeLocale(); + const currentLocale = globalize.getCurrentDateTimeLocale(); if (currentLocale) { return date.toLocaleTimeString(currentLocale, options); @@ -218,19 +218,19 @@ import globalize from 'globalize'; }); } - var time = toLocaleTimeString(date); + let time = toLocaleTimeString(date); - var timeLower = time.toLowerCase(); + const timeLower = time.toLowerCase(); if (timeLower.indexOf('am') !== -1 || timeLower.indexOf('pm') !== -1) { time = timeLower; - var hour = date.getHours() % 12; - var suffix = date.getHours() > 11 ? 'pm' : 'am'; + let hour = date.getHours() % 12; + const suffix = date.getHours() > 11 ? 'pm' : 'am'; if (!hour) { hour = 12; } - var minutes = date.getMinutes(); + let minutes = date.getMinutes(); if (minutes < 10) { minutes = '0' + minutes; @@ -240,7 +240,7 @@ import globalize from 'globalize'; time = hour + minutes + suffix; } else { - var timeParts = time.split(':'); + const timeParts = time.split(':'); // Trim off seconds if (timeParts.length > 2) { @@ -260,8 +260,8 @@ import globalize from 'globalize'; throw new Error('date cannot be null'); } - var yesterday = new Date(); - var day = yesterday.getDate() + offsetInDays; + const yesterday = new Date(); + const day = yesterday.getDate() + offsetInDays; yesterday.setDate(day); // automatically adjusts month/year appropriately @@ -281,4 +281,4 @@ import globalize from 'globalize'; } }; -/*eslint-enable indent */ +/* eslint-enable indent */