diff --git a/changelog/15743.txt b/changelog/15743.txt new file mode 100644 index 0000000000000..2e1183649b4b6 --- /dev/null +++ b/changelog/15743.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fixes client count timezone bug +``` \ No newline at end of file diff --git a/ui/app/helpers/parse-date-string.js b/ui/app/helpers/parse-date-string.js index b4780c02c853c..9535153e64784 100644 --- a/ui/app/helpers/parse-date-string.js +++ b/ui/app/helpers/parse-date-string.js @@ -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? diff --git a/ui/app/routes/vault/cluster/clients/index.js b/ui/app/routes/vault/cluster/clients/index.js index f830881389347..e0d3c82b821a1 100644 --- a/ui/app/routes/vault/cluster/clients/index.js +++ b/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 }) => { @@ -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); } } } diff --git a/ui/tests/unit/helpers/parse-date-string-test.js b/ui/tests/unit/helpers/parse-date-string-test.js index 8297a2ab901ba..57242fa7edee1 100644 --- a/ui/tests/unit/helpers/parse-date-string-test.js +++ b/ui/tests/unit/helpers/parse-date-string-test.js @@ -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); });