All files / modules/20-rbac/modals/TokenModal/views utils.tsx

91.3% Statements 21/23
81.82% Branches 9/11
100% Functions 4/4
89.47% Lines 17/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45              11x   11x   11x 40x     11x 14x 12x 2x     2x     11x 7x       6x   1x           11x 8x 2x   6x      
/*
 * Copyright 2022 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import { getReadableDateTime } from '@common/utils/dateUtils'
 
export const DATE_FORMAT = 'MM/DD/YYYY'
 
export const hasNoExpiryDate = (value?: number): boolean => {
  return getReadableDateTime(value, DATE_FORMAT) === '12/31/2099'
}
 
export const getSelectedExpiration = (value?: number): string => {
  if (!value) {
    return '30'
  } else Iif (hasNoExpiryDate(value)) {
    return '-1'
  }
  return 'custom'
}
 
export const getSelectedExpirationDate = (value: string): string => {
  switch (value) {
    case '30':
    case '90':
    case '180':
      return getReadableDateTime(new Date().setDate(new Date().getDate() + parseInt(value)), DATE_FORMAT)
    case '-1':
      return '12/31/2099'
    default:
      return ''
  }
}
 
export const getExpirationDate = (value?: number): string => {
  if (value) {
    return getReadableDateTime(value, DATE_FORMAT)
  } else {
    return getSelectedExpirationDate(getSelectedExpiration(value))
  }
}