date time converted to locale

This commit is contained in:
Arvind Tiwari 2017-10-06 04:11:40 +05:30
parent 4dbf08f995
commit 8e5654bdb5
2 changed files with 23 additions and 9 deletions

View file

@ -376,3 +376,11 @@
color: #999; color: #999;
fill: #999; fill: #999;
} }
.locale_date {
opacity: 0;
}
.locale_date.done{
opacity: 1;
}

View file

@ -32,11 +32,11 @@
{% endif %} {% endif %}
<p> <p>
<strong>{% trans "Date" %}:</strong> <strong>{% trans "Date" %}:</strong>
<span id="order-created_at"> <span class="locale_date">
{% if order %} {% if order %}
{{order.created_at|date:'Y-m-d H:i'}} {{order.created_at|date:'Y-m-d h:i a'}}
{% else %} {% else %}
{% now "Y-m-d H:i" %} {% now "Y-m-d h:i a" %}
{% endif %} {% endif %}
</span> </span>
</p> </p>
@ -107,7 +107,9 @@
{% if vm.created_at %} {% if vm.created_at %}
<p> <p>
<span>{% trans "Period" %}: </span> <span>{% trans "Period" %}: </span>
<span>{{ vm.created_at|date:'Y/m/d' }} - {{ subscription_end_date|date:'Y/m/d' }}</span> <span>
<span class="locale_date" data-format="YYYY/MM/DD">{{ vm.created_at }}</span> - <span class="locale_date" data-format="YYYY/MM/DD">{{ subscription_end_date }}</span>
</span>
</p> </p>
{% endif %} {% endif %}
<p> <p>
@ -194,12 +196,16 @@
<script type="text/javascript"> <script type="text/javascript">
{% trans "Some problem encountered. Please try again later." as err_msg %} {% trans "Some problem encountered. Please try again later." as err_msg %}
var create_vm_error_message = '{{err_msg|safe}}'; var create_vm_error_message = '{{err_msg|safe}}';
window.onload = function () { window.onload = function () {
var locale_date = moment.utc(document.getElementById("order-created_at").textContent, 'YYYY-MM-DD HH:mm').toDate(); var locale_dates = document.getElementsByClassName("locale_date");
locale_date = moment(locale_date).format("YYYY-MM-DD h:mm:ss a"); var formats = ['YYYY-MM-DD hh:mm a', 'YYYY/MM/DD']
document.getElementById('order-created_at').innerHTML = locale_date; var i;
for (i = 0; i < locale_dates.length; i++) {
var oldDate = moment.utc(locale_dates[i].textContent, formats);
var outputFormat = locale_dates[i].getAttribute('data-format') || oldDate._f;
locale_dates[i].innerHTML = oldDate.local().format(outputFormat);
locale_dates[i].className += ' done';
}
}; };
</script> </script>
{%endblock%} {%endblock%}