From d4b515f0628ca5fe5a2f57a0e2626a5934f7b151 Mon Sep 17 00:00:00 2001 From: giuliof Date: Thu, 22 Nov 2018 15:44:39 +0100 Subject: [PATCH] [F.END] Date formatting w/ moment.js --- frontend/frontend.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/frontend.js b/frontend/frontend.js index d513981..8e0ffe8 100644 --- a/frontend/frontend.js +++ b/frontend/frontend.js @@ -1,3 +1,4 @@ +// Require moment.js (with locales) function Get(yourUrl){ var Httpreq = new XMLHttpRequest(); Httpreq.open("GET",yourUrl,false); @@ -7,17 +8,17 @@ function Get(yourUrl){ var json_obj = JSON.parse(Get("https://golem.linux.it/cgi/zerocalcare/main.py?interval=4weeks")); console.log("this is the JSON: "+JSON.stringify(json_obj)); -fmt_date = { weekday: 'short', month: 'long', day: 'numeric' }; -fmt_time = { hour: 'numeric', minute: 'numeric'}; + +moment.locale('it'); for (i in json_obj) { var time_str; - var date = new Date(json_obj[i]["DATETIME"]) + var date = moment(json_obj[i]["DATETIME"]) console.log(JSON.stringify(json_obj[i])); document.write('
'+json_obj[i]["NAME"]+'
'); - document.write("
📅 "+date.toLocaleDateString("it-IT", fmt_date)+"
"); + document.write("
📅 "+date.format("ddd D MMMM")+"
"); if (json_obj[i]["ALLDAY"] == true) time_str = "Tutto il giorno" else - time_str = date.toLocaleString("it-IT", fmt_time) + time_str =date.format("H:mm") document.write("
⏰ "+time_str+"
"); }