Commit 62ee9ee0 authored by Romain Loth's avatar Romain Loth Committed by delanoe

[fix] there was a date format problem in mygraphs updating

parent 6b1157d3
......@@ -13,7 +13,7 @@ from collections import defaultdict
import csv
_node_available_fields = ['id', 'parent_id', 'name', 'typename', 'hyperdata', 'ngrams']
_node_available_fields = ['id', 'parent_id', 'name', 'typename', 'hyperdata', 'ngrams', 'date']
_node_default_fields = ['id', 'parent_id', 'name', 'typename']
_node_available_types = NODETYPES
......
......@@ -132,12 +132,13 @@
return false
}
// also replace template variables (thx c24b!)
resultHtml = resultHtml.replace(/%%project_id%%/g, projectId);
resultHtml = resultHtml.replace(/%%corpus_id%%/g, corpusId);
resultHtml = resultHtml.replace(/%%cooc_id%%/g, coocId);
resultHtml = resultHtml.replace(/%%cooc_name%%/g, coocName);
resultHtml = resultHtml.replace(/%%cooc_date%%/g, coocDate);
resultHtml = resultHtml.replace(/%%cooc_date%%/g, formatDateLikeDjango(coocDate));
if (typeof nbEdges != 'undefined' && typeof nbNodes != 'undefined') {
resultHtml = resultHtml.replace(/%%nb_nodes%%/g, nbNodes);
......@@ -291,6 +292,37 @@
clearTimeout(currentJob)
}
// raw DB format: "2016-10-04T15:00:35Z" (ISOString)
// -----------------------
//
// but django default format: Oct. 4, 2016, 3:00 p.m.
// ------------------------
// cf. docs.djangoproject.com/en/dev/ref/settings/#date-format
//
// POSSIBLE: remove UTC from django and here (current timezone more practical)
function formatDateLikeDjango(isoDateTimeStr) {
asDate = new Date(isoDateTimeStr)
// ex: "Oct 4, 2016"
var newDateStr = asDate.toLocaleDateString(
'en-US',
{ 'year': 'numeric',
'month': 'short',
'day': 'numeric' })
// ex: 3:00 pm
var newTimeStr = asDate.toLocaleTimeString(
'en-US',
{ 'hour12': true,
'timeZone': 'UTC',
'hour': '2-digit',
'minute':'numeric'})
.toLowerCase()
// ex Oct 4, 2016, 3:00 pm => close enough !
return newDateStr + ', ' + newTimeStr
}
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment