* [Bugfix] 修复英文时间时期的bug

* [bugfix] 修复session时间日期的问题

* [Bugfix] 修改时间日志格式化错误

* [Update] 修改函数名称

* [Update] 修改函数顺序

* [Update] 注释部分迁移文件内容
pull/3009/head
老广 2019-07-22 17:15:24 +08:00 committed by GitHub
parent 5f59c729b7
commit 5db704f793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 33 deletions

View File

@ -51,7 +51,7 @@ function initAssetUserTable() {
} else {
innerHtml = '<i class="fa fa-circle text-warning"></i>'
}
var dateManual = formatDateAsCN(cellData.datetime);
var dateManual = toSafeLocalDateStr(cellData.datetime);
var dataContent = testDatetime + dateManual;
innerHtml = "<a data-toggle='popover' data-content='" + dataContent + "'" + 'data-placement="auto bottom"' + ">" + innerHtml + "</a>";
$(td).html(innerHtml);
@ -59,7 +59,7 @@ function initAssetUserTable() {
},
{
targets: 6, createdCell: function (td, cellData) {
var data = formatDateAsCN(cellData);
var data = toSafeLocalDateStr(cellData);
$(td).html(data);
},
},

View File

@ -159,7 +159,7 @@ function initTable() {
} else {
innerHtml = '<i class="fa fa-circle text-warning"></i>'
}
var dateManual = formatDateAsCN(cellData.datetime);
var dateManual = toSafeLocalDateStr(cellData.datetime);
var dataContent = testDatetime + dateManual;
innerHtml = "<a data-toggle='popover' data-content='" + dataContent + "'" + 'data-placement="auto bottom"' + ">" + innerHtml + "</a>";
$(td).html(innerHtml);

View File

@ -82,7 +82,7 @@ function initTable() {
select: [],
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var d = formatDateAsCN(cellData);
var d = toSafeLocalDateStr(cellData);
$(td).html(d);
}},
{targets: 2, createdCell: function (td, cellData) {

View File

@ -109,7 +109,7 @@ $(document).ready(function () {
}
}},
{targets: 6, createdCell: function (td, cellData) {
var d = formatDateAsCN(cellData);
var d = toSafeLocalDateStr(cellData);
$(td).html(d)
}},
{targets: 7, createdCell: function (td, cellData, rowData) {

View File

@ -88,7 +88,7 @@ function initTable() {
select: [],
columnDefs: [
{targets: 1, createdCell: function (td, cellData, rowData) {
var d = formatDateAsCN(cellData);
var d = toSafeLocalDateStr(cellData);
$(td).html(d);
}},

View File

@ -103,9 +103,9 @@ class Migration(migrations.Migration):
name='nodes',
field=models.ManyToManyField(blank=True, related_name='granted_by_permissions', to='assets.Node', verbose_name='Nodes'),
),
migrations.RunPython(
code=migrate_node_permissions,
),
# migrations.RunPython(
# code=migrate_node_permissions,
# ),
migrations.RunPython(
code=migrate_system_assets_relation,
),

View File

@ -1091,7 +1091,7 @@ function objectAttrsIsList(obj, attrs) {
function objectAttrsIsDatetime(obj, attrs) {
attrs.forEach(function (attr) {
obj[attr] = formatDateAsCN(obj[attr]);
obj[attr] = toSafeDateISOStr(obj[attr]);
})
}
@ -1105,29 +1105,37 @@ function objectAttrsIsBool(obj, attrs) {
})
}
function cleanDate(d) {
if (typeof d === 'number'){
return d
}
if (typeof d === "string") {
d = d.replaceAll('-', '/')
}
for (var i=0; i<2; i++) {
if (isNaN(Date.parse(d))) {
d = d.split('+')[0].trimRight();
} else {
return d
function cleanDateStr(d) {
for (var i=0;i<3;i++) {
if (!isNaN(Date.parse(d))){
return d;
}
if (!isNaN(Number(d))) {
return d;
}
switch (i) {
case 0:
d = d.replaceAll('-', '/');
break;
case 1:
d = d.split('+')[0].trimRight();
break;
}
}
return ''
return null;
}
function safeDate(s) {
s = cleanDate(s);
s = cleanDateStr(s);
return new Date(s)
}
function formatDateAsCN(d) {
function toSafeDateISOStr(s) {
var d = safeDate(s);
return d.toISOString();
}
function toSafeLocalDateStr(d) {
var date = safeDate(d);
var date_s = date.toLocaleString(navigator.language, {hour12: false});
return date_s.split("/").join('-')
@ -1149,7 +1157,7 @@ function getTimeUnits(u) {
"m": "分",
"s": "秒",
};
if (navigator.language || "zh-CN") {
if (navigator.language === "zh-CN") {
return units[u]
}
return u

View File

@ -7,7 +7,7 @@
<script src="{% static "js/plugins/toastr/toastr.min.js" %}"></script>
<script src="{% static "js/inspinia.js" %}"></script>
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script src="{% static "js/jumpserver.js" %}?v=1"></script>
<script src="{% static "js/jumpserver.js" %}?v=2"></script>
<script>
activeNav();
$(document).ready(function(){

View File

@ -193,7 +193,7 @@ function initTable() {
$(td).html(data);
}},
{targets: 6, createdCell: function (td, cellData) {
var data = formatDateAsCN(cellData*1000);
var data = toSafeLocalDateStr(cellData*1000);
$(td).html(data);
}},
],

View File

@ -104,8 +104,8 @@ var dateFrom = "{{ date_from.timestamp }}";
var dateTo = "{{ date_to.timestamp }}";
function initTable() {
dateFrom = formatDateAsCN(dateFrom * 1000);
dateTo = formatDateAsCN(dateTo * 1000);
dateFrom = toSafeDateISOStr(dateFrom * 1000);
dateTo = toSafeDateISOStr(dateTo * 1000);
sessionListUrl = setUrlParam(sessionListUrl, "date_from", dateFrom);
sessionListUrl = setUrlParam(sessionListUrl, "date_to", dateTo);
var options = {
@ -121,7 +121,7 @@ function initTable() {
$(td).html(data);
}},
{targets: 9, createdCell: function (td, cellData) {
var data = formatDateAsCN(cellData);
var data = toSafeLocalDateStr(cellData);
$(td).html(data);
}},
{targets: 10, createdCell: function (td, cellData, rowData) {
@ -201,7 +201,7 @@ $(document).ready(function() {
return
}
var value = $(this).val() + ' 0:0:0';
var date = formatDateAsCN(value);
var date = toSafeDateISOStr(value);
var url = table.ajax.url();
url = setUrlParam(url, "date_from", date);
table.ajax.url(url);
@ -212,7 +212,7 @@ $(document).ready(function() {
return
}
var value = $(this).val() + ' 23:59:59';
var date = formatDateAsCN(value);
var date = toSafeDateISOStr(value);
var url = table.ajax.url();
url = setUrlParam(url, "date_to", date);
table.ajax.url(url);