moved date functions to utils.js

This commit is contained in:
azivner 2017-09-30 22:36:14 -04:00
parent d0cc5f4a5f
commit 16eb7a0639
2 changed files with 22 additions and 22 deletions

View file

@ -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();

View file

@ -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);
}