Skip to content

Commit b799944

Browse files
authored
Merge pull request #2392 from devtron-labs/fix/time-range-modal
fix: parsing issues with date and time
2 parents 60985dc + 68f41a3 commit b799944

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/components/app/details/appDetails/AppMetrics.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import HostErrorImage from '../../../../assets/img/ic-error-hosturl.png'
5151
import { ReactComponent as DropDownIcon } from '../../../../assets/icons/appstatus/ic-chevron-down.svg'
5252
import { getModuleInfo } from '../../../v2/devtronStackManager/DevtronStackManager.service'
5353
import { ModuleStatus } from '../../../v2/devtronStackManager/DevtronStackManager.type'
54+
import { APP_METRICS_CALENDAR_INPUT_DATE_FORMAT } from './constants'
5455

5556
export const AppMetrics: React.FC<{
5657
appName: string
@@ -104,8 +105,8 @@ export const AppMetrics: React.FC<{
104105
endDate,
105106
})
106107
setCalendarInput({
107-
startDate: startDate?.format('DD-MM-YYYY hh:mm:ss'),
108-
endDate: endDate?.format('DD-MM-YYYY hh:mm:ss') || '',
108+
startDate: startDate?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT),
109+
endDate: endDate?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT) || '',
109110
})
110111
}
111112

src/components/app/details/appDetails/GraphsModal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { AppMetricsTabType, ChartType, StatusType, ChartTypes, StatusTypes, AppM
2323
import { getIframeSrc, isK8sVersionValid, ThroughputSelect, getCalendarValue, LatencySelect } from './utils'
2424
import { ReactComponent as GraphIcon } from '../../../../assets/icons/ic-graph.svg'
2525
import { DEFAULTK8SVERSION } from '../../../../config'
26+
import { APP_METRICS_CALENDAR_INPUT_DATE_FORMAT } from './constants'
2627

2728
export const ChartNames = {
2829
cpu: 'CPU Usage',
@@ -198,8 +199,8 @@ export class GraphModal extends Component<GraphModalProps, GraphModalState> {
198199
endDate: end,
199200
},
200201
calendarInputs: {
201-
startDate: start?.format('DD MM YYYY hh:mm:ss'),
202-
endDate: end?.format('DD MM YYYY hh:mm:ss') || '',
202+
startDate: start?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT),
203+
endDate: end?.format(APP_METRICS_CALENDAR_INPUT_DATE_FORMAT) || '',
203204
},
204205
})
205206
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const APP_METRICS_CALENDAR_INPUT_DATE_FORMAT = 'DD-MM-YYYY hh:mm:ss'

src/components/app/details/appDetails/utils.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { AggregationKeys } from '../../types'
2121
import { getVersionArr, isVersionLessThanOrEqualToTarget, DayPickerRangeControllerPresets } from '../../../common'
2222
import { ReactComponent as ArrowDown } from '../../../../assets/icons/ic-chevron-down.svg'
2323
import { ChartTypes, AppMetricsTabType, StatusType, StatusTypes } from './appDetails.type'
24-
import { ZERO_TIME_STRING, Nodes, NodeType, ACTION_STATE, ButtonStyleType } from '@devtron-labs/devtron-fe-common-lib'
24+
import { ZERO_TIME_STRING, Nodes, NodeType, ACTION_STATE, ButtonStyleType, prefixZeroIfSingleDigit } from '@devtron-labs/devtron-fe-common-lib'
2525
import CreatableSelect from 'react-select/creatable'
2626

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

342343
return isNaN(parsedDate) ? dateString : parsedDate.toString()

0 commit comments

Comments
 (0)