From 16eb7a063918bab3d7cff8b52632e20662763809 Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 30 Sep 2017 22:36:14 -0400 Subject: [PATCH] moved date functions to utils.js --- static/js/init.js | 22 ---------------------- static/js/utils.js | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/static/js/init.js b/static/js/init.js index 22bea3c75..a08ba82ec 100644 --- a/static/js/init.js +++ b/static/js/init.js @@ -15,28 +15,6 @@ $(document).bind('keydown', 'alt+s', function() { $("input[name=search]").focus(); }); -function getDateFromTS(timestamp) { - // Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling - // see https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript - const utcDate = new Date(timestamp * 1000); - - const localDate = new Date(utcDate.getTime() - utcDate.getTimezoneOffset() * 60 * 1000); - - return localDate; -} - -function formatTime(date) { - return (date.getHours() <= 9 ? "0" : "") + date.getHours() + ":" + (date.getMinutes() <= 9 ? "0" : "") + date.getMinutes(); -} - -function formatDate(date) { - return date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear(); -} - -function formatDateTime(date) { - return formatDate(date) + " " + formatTime(date); -} - // hide (toggle) everything except for the note content for distraction free writing $(document).bind('keydown', 'alt+t', function() { const date = new Date(); diff --git a/static/js/utils.js b/static/js/utils.js index 98140d8c5..6f7b02b46 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -47,4 +47,26 @@ function uint8ToBase64(u8Arr) { function base64ToUint8Array(base64encoded) { return new Uint8Array(atob(base64encoded).split("").map(function(c) { return c.charCodeAt(0); })); +} + +function getDateFromTS(timestamp) { + // Date accepts number of milliseconds since epoch so UTC timestamp works without any extra handling + // see https://stackoverflow.com/questions/4631928/convert-utc-epoch-to-local-date-with-javascript + const utcDate = new Date(timestamp * 1000); + + const localDate = new Date(utcDate.getTime() - utcDate.getTimezoneOffset() * 60 * 1000); + + return localDate; +} + +function formatTime(date) { + return (date.getHours() <= 9 ? "0" : "") + date.getHours() + ":" + (date.getMinutes() <= 9 ? "0" : "") + date.getMinutes(); +} + +function formatDate(date) { + return date.getDate() + ". " + (date.getMonth() + 1) + ". " + date.getFullYear(); +} + +function formatDateTime(date) { + return formatDate(date) + " " + formatTime(date); } \ No newline at end of file