From f7e9cceb70170ddff2ea3b50badd245a7fb88fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Tue, 23 Aug 2016 04:35:09 +0200 Subject: [PATCH] Utilisation de moment.js sur K-Psul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parce que bon, ça fait un peu plus sérieux --- kfet/templates/kfet/kpsul.html | 31 ++++++++++++------------------- kfet/views.py | 2 +- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 51a178d0..4e85eaf0 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -8,6 +8,9 @@ + + + {% endblock %} {% block title %}K-Psul{% endblock %} @@ -280,14 +283,8 @@ $(document).ready(function() { var at_formated = ''; if (checkout_data['last_statement_at']) { last_statement_container.html(last_statement_html_default); - at = new Date(checkout_data['last_statement_at']); - var at_date = at.getDate(); - var at_month = at.getMonth()+1; - var at_year = at.getFullYear(); - var at_hours = at.getHours(); - var at_minutes = (at.getMinutes() < 10 ? '0' : '') + at.getMinutes(); - var at_seconds = (at.getSeconds() < 10 ? '0' : '') + at.getSeconds(); - at_formated = at_date+'/'+at_month+'/'+at_year+' à '+at_hours+':'+at_minutes; + var at = moment.tz(checkout_data['last_statement_at'], 'UTC'); + at_formated = at.tz('Europe/Paris').format('DD/MM/YY à HH:mm'); } else { last_statement_container.html(''); } @@ -1003,11 +1000,8 @@ $(document).ready(function() { function getOpegroupHtml(opegroup) { var opegroup_html = $(history_operationgroup_html); - var at = new Date(opegroup['at']); - var at_hours = (at.getHours() < 10 ? '0' : '') + at.getHours(); - var at_minutes = (at.getMinutes() < 10 ? '0' : '') + at.getMinutes(); - var at_seconds = (at.getSeconds() < 10 ? '0' : '') + at.getSeconds(); - var at_formated = at_hours+':'+at_minutes+':'+at_seconds; + var at = moment.tz(opegroup['at'], 'UTC'); + var at_formated = at.tz('Europe/Paris').format('HH:mm:ss'); var amount = parseFloat(opegroup['amount']); var trigramme = opegroup['on_acc__trigramme']; if (opegroup['on_acc__trigramme'] == 'LIQ') { @@ -1044,17 +1038,16 @@ $(document).ready(function() { } var history_day_default_html = '
'; - var months = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre']; function checkOrCreateDay(at) { - var at = new Date(at); + var at = moment.tz(at, 'UTC').tz('Europe/Paris'); var mostRecentDay = history_container.find('.day').first(); - if (mostRecentDay.length == 0 || at.getMonth() != mostRecentDay.attr('data-month') || at.getDate() != mostRecentDay.attr('data-day')) { + if (mostRecentDay.length == 0 || at.month() != mostRecentDay.attr('data-month') || at.date() != mostRecentDay.attr('data-day')) { var day_html = $(history_day_default_html); day_html - .attr('data-month', at.getMonth()) - .attr('data-day', at.getDate()) - .text(at.getDate()+' '+months[at.getMonth()]); + .attr('data-month', at.month()) + .attr('data-day', at.date()) + .text(at.format('D MMMM')); history_container.prepend(day_html); } } diff --git a/kfet/views.py b/kfet/views.py index 2b7ed195..009cb800 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -984,7 +984,7 @@ def kpsul_history(request): 'id', 'amount', 'at', 'checkout_id', 'is_cof', 'valid_by__trigramme', 'on_acc__trigramme') .select_related('valid_by', 'on_acc') - .filter(at__gt=timezone.now()-timedelta(hours=4))) + .filter(at__gt=timezone.now()-timedelta(hours=24))) opegroups = { opegroup['id']:opegroup for opegroup in opegroups_list } for opegroup in opegroups: opegroups[opegroup]['opes'] = []