Skip to content

Commit

Permalink
Client count timezone fix (#15743)
Browse files Browse the repository at this point in the history
* This is the backport for #15167
Client count went through major refactoring in 1.10 and as a result
straightforward backport was not possible.

* Added changelog

* Fix test
  • Loading branch information
arnav28 committed Jun 1, 2022
1 parent 991d412 commit 379bf00
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
3 changes: 3 additions & 0 deletions changelog/15743.txt
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fixes client count timezone bug
```
8 changes: 5 additions & 3 deletions ui/app/helpers/parse-date-string.js
Expand Up @@ -8,9 +8,11 @@ export function parseDateString(date, separator = '-') {
if (datePieces[0] < 1 || datePieces[0] > 12) {
throw new Error('Not a valid month value');
}
let firstOfMonth = new Date(datePieces[1], datePieces[0] - 1, 1);
if (isValid(firstOfMonth)) {
return firstOfMonth;
// Since backend converts the timezone to UTC, sending the first (1) as start or end date can cause the month to change.
// To mitigate this impact of timezone conversion, hard coding the date to avoid month change.
let date = new Date(datePieces[1], datePieces[0] - 1, 10);
if (isValid(date)) {
return date;
}
}
// what to return if not valid?
Expand Down
9 changes: 3 additions & 6 deletions ui/app/routes/vault/cluster/clients/index.js
@@ -1,7 +1,7 @@
import Route from '@ember/routing/route';
import ClusterRoute from 'vault/mixins/cluster-route';
import { hash } from 'rsvp';
import { getTime } from 'date-fns';
import { formatRFC3339 } from 'date-fns';
import { parseDateString } from 'vault/helpers/parse-date-string';

const getActivityParams = ({ tab, start, end }) => {
Expand All @@ -14,16 +14,13 @@ const getActivityParams = ({ tab, start, end }) => {
if (start) {
let startDate = parseDateString(start);
if (startDate) {
// TODO: Replace with formatRFC3339 when date-fns is updated
// converts to milliseconds, divide by 1000 to get epoch
params.start_time = getTime(startDate) / 1000;
params.start_time = formatRFC3339(startDate);
}
}
if (end) {
let endDate = parseDateString(end);
if (endDate) {
// TODO: Replace with formatRFC3339 when date-fns is updated
params.end_time = getTime(endDate) / 1000;
params.end_time = formatRFC3339(endDate);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ui/tests/unit/helpers/parse-date-string-test.js
Expand Up @@ -4,13 +4,13 @@ import { compareAsc } from 'date-fns';

module('Unit | Helpers | parse-date-string', function() {
test('it returns the first of the month when date like MM-yyyy passed in', function(assert) {
let expected = new Date(2020, 3, 1);
let expected = new Date(2020, 3, 10);
let result = parseDateString('04-2020');
assert.equal(compareAsc(expected, result), 0);
});

test('it can handle a date format like MM/yyyy', function(assert) {
let expected = new Date(2020, 11, 1);
let expected = new Date(2020, 11, 10);
let result = parseDateString('12/2020', '/');
assert.equal(compareAsc(expected, result), 0);
});
Expand Down

0 comments on commit 379bf00

Please sign in to comment.