Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ export default class IndexTable extends Component {
name: 'Last Signed In',
title: t('Last Signed In'),
defaultContent: '-',
render: DataTablesHelpers.renderTime,
render: DataTablesHelpers.renderTime(this.session.data.authenticated.analytics_timezone),
},
{
data: 'created_at',
type: 'date',
name: 'Created',
title: t('Created'),
defaultContent: '-',
render: DataTablesHelpers.renderTime,
render: DataTablesHelpers.renderTime(this.session.data.authenticated.analytics_timezone),
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class IndexTable extends Component {
type: 'date',
title: 'Created',
defaultContent: '-',
render: DataTablesHelpers.renderTime,
render: DataTablesHelpers.renderTime(this.session.data.authenticated.analytics_timezone),
},
{
data: 'registration_source',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line ember/no-classic-components
import Component from '@ember/component';
import { action, computed } from '@ember/object';
import { inject } from '@ember/service';
import { observes } from '@ember-decorators/object';
import Logs from 'api-umbrella-admin-ui/models/stats/logs';
import DataTablesHelpers from 'api-umbrella-admin-ui/utils/data-tables-helpers';
Expand All @@ -22,6 +23,9 @@ marked.use({
export default class ResultsTable extends Component {
tagName = '';

@inject('session')
session;

@action
didInsert(element) {
this.table = $(element).find('table').DataTable({
Expand Down Expand Up @@ -58,7 +62,7 @@ export default class ResultsTable extends Component {
type: 'date',
title: 'Time',
defaultContent: '-',
render: DataTablesHelpers.renderTime,
render: DataTablesHelpers.renderTime(this.session.data.authenticated.analytics_timezone),
},
{
data: 'request_method',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line ember/no-classic-components
import Component from '@ember/component';
import { action, computed } from '@ember/object';
import { inject } from '@ember/service';
import { observes } from '@ember-decorators/object';
import DataTablesHelpers from 'api-umbrella-admin-ui/utils/data-tables-helpers';
import classic from 'ember-classic-decorator';
Expand All @@ -14,6 +15,9 @@ import numeral from 'numeral';
export default class ResultsTable extends Component {
tagName = '';

@inject('session')
session;

@action
didInsert(element) {
this.table = $(element).find('table').DataTable({
Expand Down Expand Up @@ -60,7 +64,7 @@ export default class ResultsTable extends Component {
type: 'date',
title: 'Signed Up',
defaultContent: '-',
render: DataTablesHelpers.renderTime,
render: DataTablesHelpers.renderTime(this.session.data.authenticated.analytics_timezone),
},
{
data: 'hits',
Expand All @@ -79,7 +83,7 @@ export default class ResultsTable extends Component {
type: 'date',
title: 'Last Request',
defaultContent: '-',
render: DataTablesHelpers.renderTime,
render: DataTablesHelpers.renderTime(this.session.data.authenticated.analytics_timezone),
},
{
data: 'use_description',
Expand Down
12 changes: 7 additions & 5 deletions src/api-umbrella/admin-ui/app/utils/data-tables-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ export default {
}
},

renderTime(value, type) {
if(type === 'display' && value && value !== '-') {
return moment(value).format('YYYY-MM-DD HH:mm:ss');
}
renderTime(timezone) {
return function(value, type) {
if(type === 'display' && value && value !== '-') {
return moment(value).tz(timezone).format('YYYY-MM-DD HH:mm:ss z');
}

return value;
return value;
}
},
};
7 changes: 3 additions & 4 deletions src/api-umbrella/utils/time.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ local null = ngx.null
local date = icu_date.new()
local format_iso8601 = icu_date.formats.pattern("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
local format_iso8601_ms = icu_date.formats.pattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ")
local format_csv = icu_date.formats.pattern("yyyy-MM-dd HH:mm:ss")
local format_postgres = icu_date.formats.pattern("yyyy-MM-dd HH:mm:ss.SSSSxxx")
local format_postgres_no_millis = icu_date.formats.pattern("yyyy-MM-dd HH:mm:ssxxx")

Expand Down Expand Up @@ -80,7 +79,7 @@ function _M.timestamp_ms_to_csv(timestamp)
end

date:set_millis(timestamp)
return date:format(format_csv)
return date:format(format_iso8601_ms)
end

function _M.iso8601_to_timestamp(string)
Expand Down Expand Up @@ -116,7 +115,7 @@ function _M.iso8601_to_csv(string)
end

date:parse(format_iso8601, string)
return date:format(format_csv)
return date:format(format_iso8601)
end

function _M.iso8601_ms_to_csv(string)
Expand All @@ -125,7 +124,7 @@ function _M.iso8601_ms_to_csv(string)
end

date:parse(format_iso8601_ms, string)
return date:format(format_csv)
return date:format(format_iso8601_ms)
end

function _M.opensearch_to_csv(value)
Expand Down
22 changes: 22 additions & 0 deletions test/admin_ui/test_stats_logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,26 @@ def test_filter_options
"is not null",
]
end

def test_table_displays_time_in_local_timezone
FactoryBot.create(:log_item, :request_at => Time.parse("2015-01-16T06:06:28.816Z").utc, :request_method => "OPTIONS")
LogItem.refresh_indices!

admin_login
visit "/admin/#/stats/logs?search=&start_at=2015-01-12&end_at=2015-01-18&interval=day"
refute_selector(".busy-blocker")

assert_text("2015-01-15 23:06:28 MST")
end

def test_table_displays_time_in_local_timezone_during_dst
FactoryBot.create(:log_item, :request_at => Time.parse("2015-07-16T06:06:28.816Z").utc, :request_method => "OPTIONS")
LogItem.refresh_indices!

admin_login
visit "/admin/#/stats/logs?search=&start_at=2015-07-12&end_at=2015-07-18&interval=day"
refute_selector(".busy-blocker")

assert_text("2015-07-16 00:06:28 MDT")
end
end
22 changes: 22 additions & 0 deletions test/apis/admin/stats/test_logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,26 @@ def test_no_results_non_existent_indices
"recordsTotal" => 0,
}, data)
end

def test_csv_timestamps_in_iso8601_utc_format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks good, but there's one other semi-related test that's failing now: https://github.com/NatLabRockies/api-umbrella/actions/runs/21634777879/job/62359925312#step:5:385

@user1.created_at.utc.strftime("%Y-%m-%d %H:%M:%S"),
"2",
"2015-01-16 00:00:00",
@user1.use_description,
], csv[1])
assert_equal([
@user2.email,
@user2.first_name,
@user2.last_name,
@user2.website,
@user2.registration_source,
@user2.created_at.utc.strftime("%Y-%m-%d %H:%M:%S"),
"1",
"2015-01-17 00:00:00",

I think you'll need to update those tests to call user1.created_at.utc.iso8601 and then updated the hard-coded "2015-01-16 00:00:00" strings into ISO8601 format.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you! I was trying to figure out what I was missing on these failures. Fixed!

FactoryBot.create(:log_item, :request_at => Time.parse("2015-01-16T06:06:28.816Z").utc, :request_user_agent => unique_test_id)
LogItem.refresh_indices!

response = Typhoeus.get("https://127.0.0.1:9081/admin/stats/logs.csv", http_options.deep_merge(admin_session).deep_merge({
:params => {
"start_at" => "2015-01-13",
"end_at" => "2015-01-18",
"interval" => "day",
"start" => "0",
"length" => "10",
},
}))

assert_response_code(200, response)

csv = CSV.parse(response.body)
assert_equal(2, csv.length)
assert_equal("Time", csv[0][0])
assert_equal("2015-01-16T06:06:28.816Z", csv[1][0])
end
end
8 changes: 4 additions & 4 deletions test/apis/admin/stats/test_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def test_csv_download
@user1.last_name,
@user1.website,
@user1.registration_source,
@user1.created_at.utc.strftime("%Y-%m-%d %H:%M:%S"),
@user1.created_at.utc.iso8601,
"2",
"2015-01-16 00:00:00",
"2015-01-16T00:00:00Z",
@user1.use_description,
], csv[1])
assert_equal([
Expand All @@ -107,9 +107,9 @@ def test_csv_download
@user2.last_name,
@user2.website,
@user2.registration_source,
@user2.created_at.utc.strftime("%Y-%m-%d %H:%M:%S"),
@user2.created_at.utc.iso8601,
"1",
"2015-01-17 00:00:00",
"2015-01-17T00:00:00Z",
@user2.use_description,
], csv[2])
end
Expand Down
Loading