Skip to content

Commit

Permalink
fix(rhsmSchemas): ent-4366 graph total display mismatch (#837)
Browse files Browse the repository at this point in the history
* dateHelpers, utc base
* rhsmSchemas, adjust for utc date
* rhsmTransformers, month-day-year current date check
  • Loading branch information
cdcabrera committed Nov 29, 2021
1 parent fcca67c commit 2706eaa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/common/dateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getCurrentDate = () =>
(helpers.DEV_MODE &&
process.env.REACT_APP_DEBUG_DEFAULT_DATETIME &&
moment.utc(process.env.REACT_APP_DEBUG_DEFAULT_DATETIME).toDate()) ||
new Date();
moment.utc().toDate();

/**
* Set a date range based on a granularity type.
Expand Down
4 changes: 2 additions & 2 deletions src/services/rhsm/rhsmSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const instancesItem = Joi.object({
display_name: Joi.string().optional().allow(null),
measurements: Joi.array().default([]),
subscription_manager_id: Joi.string().optional().allow(null),
last_seen: Joi.date().allow(null)
last_seen: Joi.date().utc().allow(null)
})
.unknown(true)
.default();
Expand All @@ -85,7 +85,7 @@ const instancesResponseSchema = Joi.object().keys({
* @type {*} Joi schema
*/
const tallyItem = Joi.object({
date: Joi.date().allow(null),
date: Joi.date().utc().allow(null),
has_data: Joi.boolean().optional().allow(null),
value: Joi.number().allow(null).default(0)
})
Expand Down
11 changes: 3 additions & 8 deletions src/services/rhsm/rhsmTranformers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import moment from 'moment';
import {
RHSM_API_RESPONSE_INSTANCES_DATA_TYPES as INSTANCES_DATA_TYPES,
RHSM_API_RESPONSE_INSTANCES_META_TYPES as INSTANCES_META_TYPES,
Expand Down Expand Up @@ -52,13 +53,7 @@ const rhsmTally = response => {
const updatedResponse = {};
const { [rhsmConstants.RHSM_API_RESPONSE_DATA]: data = [], [rhsmConstants.RHSM_API_RESPONSE_META]: meta = {} } =
response || {};
/**
* FixMe: this is a potential bug
* Under RHOSAK this can't be seen because we're using a monthly range. However, under something like RHEL
* where a "quarterly range" that spans a year+ days of the month repeat. We need to match the full date
* instead of just the day.
*/
const currentDay = dateHelpers.getCurrentDate()?.getDate();
const currentDay = moment.utc(dateHelpers.getCurrentDate()).format('MM-D-YYYY');

updatedResponse.data = data.map(
(
Expand All @@ -69,7 +64,7 @@ const rhsmTally = response => {
y: value,
date,
hasData,
isCurrentDate: date?.getDate() === currentDay
isCurrentDate: moment.utc(date).format('MM-D-YYYY') === currentDay
})
);

Expand Down

0 comments on commit 2706eaa

Please sign in to comment.