Skip to content

Commit

Permalink
Merge pull request #2392 from devtron-labs/fix/time-range-modal
Browse files Browse the repository at this point in the history
fix: parsing issues with date and time
  • Loading branch information
eshankvaish authored Jan 22, 2025
2 parents 60985dc + 68f41a3 commit b799944
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/app/details/appDetails/AppMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import HostErrorImage from '../../../../assets/img/ic-error-hosturl.png'
import { ReactComponent as DropDownIcon } from '../../../../assets/icons/appstatus/ic-chevron-down.svg'
import { getModuleInfo } from '../../../v2/devtronStackManager/DevtronStackManager.service'
import { ModuleStatus } from '../../../v2/devtronStackManager/DevtronStackManager.type'
import { APP_METRICS_CALENDAR_INPUT_DATE_FORMAT } from './constants'

export const AppMetrics: React.FC<{
appName: string
Expand Down Expand Up @@ -104,8 +105,8 @@ export const AppMetrics: React.FC<{
endDate,
})
setCalendarInput({
startDate: startDate?.format('DD-MM-YYYY hh:mm:ss'),
endDate: endDate?.format('DD-MM-YYYY hh:mm:ss') || '',
startDate: startDate?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT),
endDate: endDate?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT) || '',
})
}

Expand Down
5 changes: 3 additions & 2 deletions src/components/app/details/appDetails/GraphsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { AppMetricsTabType, ChartType, StatusType, ChartTypes, StatusTypes, AppM
import { getIframeSrc, isK8sVersionValid, ThroughputSelect, getCalendarValue, LatencySelect } from './utils'
import { ReactComponent as GraphIcon } from '../../../../assets/icons/ic-graph.svg'
import { DEFAULTK8SVERSION } from '../../../../config'
import { APP_METRICS_CALENDAR_INPUT_DATE_FORMAT } from './constants'

export const ChartNames = {
cpu: 'CPU Usage',
Expand Down Expand Up @@ -198,8 +199,8 @@ export class GraphModal extends Component<GraphModalProps, GraphModalState> {
endDate: end,
},
calendarInputs: {
startDate: start?.format('DD MM YYYY hh:mm:ss'),
endDate: end?.format('DD MM YYYY hh:mm:ss') || '',
startDate: start?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT),
endDate: end?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT) || '',
},
})
}
Expand Down
1 change: 1 addition & 0 deletions src/components/app/details/appDetails/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const APP_METRICS_CALENDAR_INPUT_DATE_FORMAT = 'DD-MM-YYYY hh:mm:ss'
5 changes: 3 additions & 2 deletions src/components/app/details/appDetails/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { AggregationKeys } from '../../types'
import { getVersionArr, isVersionLessThanOrEqualToTarget, DayPickerRangeControllerPresets } from '../../../common'
import { ReactComponent as ArrowDown } from '../../../../assets/icons/ic-chevron-down.svg'
import { ChartTypes, AppMetricsTabType, StatusType, StatusTypes } from './appDetails.type'
import { ZERO_TIME_STRING, Nodes, NodeType, ACTION_STATE, ButtonStyleType } from '@devtron-labs/devtron-fe-common-lib'
import { ZERO_TIME_STRING, Nodes, NodeType, ACTION_STATE, ButtonStyleType, prefixZeroIfSingleDigit } from '@devtron-labs/devtron-fe-common-lib'
import CreatableSelect from 'react-select/creatable'

export function getAggregator(nodeType: NodeType, defaultAsOtherResources?: boolean): AggregationKeys {
Expand Down Expand Up @@ -336,7 +336,8 @@ const getTimestampFromDateIfAvailable = (dateString: string): string => {
try {
const [day, month, yearAndTime] = dateString.split('-')
const [year, time] = yearAndTime.split(' ')
const formattedDate = `${year}-${month}-${day}T${time}`
const updatedTime = time.split(':').map((item) => ['0', '00'].includes(item) ? '00' : prefixZeroIfSingleDigit(Number(item))).join(':')
const formattedDate = `${year}-${prefixZeroIfSingleDigit(Number(month))}-${prefixZeroIfSingleDigit(Number(day))}T${updatedTime}`
const parsedDate = new Date(formattedDate).getTime()

return isNaN(parsedDate) ? dateString : parsedDate.toString()
Expand Down

0 comments on commit b799944

Please sign in to comment.