Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

  • convertStrToValidDateFormat(date: string): string
  • This function converts DD/MM/YYYY to YYYY-MM-DD. JavaScript new Date() method accept date in YYYY-MM-DD or YYYY/MM/DD format that's why we needed this method

    remarks

    This function is needed because dayjs does not work with 'DD/MM/YYYY' type of inputs

    example
    convertStrToValidDateFormat('22/11/2021');  - // Output will be '2021-11-22'
    convertStrToValidDateFormat('03/25/2015'); - // Output will be '2015-25-03'
    convertStrToValidDateFormat('03-25-2015'); - // Output will be '2015-25-03'

    Parameters

    • date: string

      Input date string in DD/MM/YYYY or DD-MM-YYYY format

    Returns string

  • dobValidationCheck(inputDob: string): boolean
  • This method Checks whether date string is Valid Date of birth or not.

    remarks

    Doesn't check for Minor (Age < 18). Checks if age is lower than 120, also if date is valid (i.e, leap year validations, no invalid month or date etc) Validations :- isValidDate(no invalid months(ex. 13), dates (ex. 32), leap year violations , Future date, formatted length = 10, age not more than 120.

    example
    dobValidationCheck('10/10/2000');  // Output will be true
    dobValidationCheck('10/10/1500'); // Output will be false

    Parameters

    • inputDob: string

    Returns boolean

  • formatDateWithBackSlash(inputDate: string): string
  • This method inserts "/" while entering dates in input element

    remarks

    This function is called while user is inputting the date in an input Not using input type as date for this use case as it forces us to use default date selector, and we have created a custom date selector and hence the need for this function arises.

    example
    formatDateWithBackSlash('121');  // Output will be '12/1'
    formatDateWithBackSlash('12'); // Output will be '12/'
    formatDateWithBackSlash('1'); // Output will be '1'
    formatDateWithBackSlash('1213'); // Output will be '12/13'
    formatDateWithBackSlash('12121212'); // Output will be '12/12/1212'

    Parameters

    • inputDate: string

      string entered in input element

    Returns string

  • getAgeFromDateOfBirth(birthDate: Date): undefined | number | ""
  • This function returns age as a number from the date of birth as an input

    example
    getAgeFromDateOfBirth(new Date());  // Output is ''
    getAgeFromDateOfBirth('Sun Oct 10 1993 05:30:00 GMT+0530 (India Standard Time)'); // Output is 28
    getAgeFromDateOfBirth('1993-10-10'); // Output is 28
    getAgeFromDateOfBirth(); // Output is ''

    Parameters

    • birthDate: Date

      birth date of a person in Date format

    Returns undefined | number | ""

  • getDateInRequiredFormat(longDateValue: Date, dateFormat?: string): undefined | string
  • This function converts date input coming from backend (generally in long format (ex. '2022-02-01T12:16:13')) to a specified format provided in 2nd paramter It converts all types of dates accepted by dayjs

    remarks

    Link for dayjs format method - https://day.js.org/docs/en/display/format

    example
    getDateInRequiredFormat('2022-02-01T12:16:13', 'DD MMM, hh:mm A');  // Output will be '01 Feb, 12:16 PM'
    getDateInRequiredFormat('2022-01-28T12:54:40', 'DD MMM, hh:mm A'); // Output will be '28 Jan, 12:54 PM'
    getDateInRequiredFormat('2022-01-25T12:08:12', 'DD MMM YYYY, hh:mm A); // Output will be '25 Jan 2022, 12:08 PM'
    getDateInRequiredFormat('2021/11/20', 'YYYY-MM-DD'); // Output will be '2021-11-20'
    getDateInRequiredFormat('21 Nov 2020', 'YYYY-MM-DD'); // Output will be '2020-11-21'
    getDateInRequiredFormat('Fri Feb 04 2022 15:24:28 GMT+0530 (India Standard Time)', 'YYYY-MM-DD'); // Output will be '2022-02-04'

    Parameters

    • longDateValue: Date

      Date input to be converted to another format. This generally comes from backend and is in long format. For example '2022-02-01T12:16:13'

    • dateFormat: string = 'DD MMM YYYY'

      Format in which the date needs to be converted to.

    Returns undefined | string

  • getMonthAbbrByIndex(monthNumber: number): string
  • This method can be used to get month name abbreviation from month number.

    remarks

    monthNumber should be in the range of 1-12

    example
    getMonthAbbrByIndex(2) // Feb will be the output
    

    Parameters

    • monthNumber: number

      Month number, eg: for Jan, it is 1

    Returns string

  • getPreviousDayDate(date: Date, daysCount?: number): undefined | Date
  • This method is used for getting previous date to the date provided through argument. argument should come through only new Date() Not doing with dayjs as no specific methods for this use case are there.

    example
    getPreviousDayDate(new Date());  // Output will be 'Thu Feb 03 2022 03:28:49 GMT+0530 (India Standard Time)'
    

    Parameters

    • date: Date

      Date as only new Date()

    • daysCount: number = 1

    Returns undefined | Date

  • getPreviousMonthDate(date: Date, monthCount?: number): undefined | Date
  • This method is used for getting previous month with same date to the date provided through argument. Not doing with dayjs as no specific methods for this use case are there.

    example
    getPreviousMonthDate('Mon Mar 15 2021 10:21:35 GMT+0530 (India Standard Time)');  // Output will be 'Mon Feb 15 2021 10:21:35 GMT+0530 (India Standard Time)'
    getPreviousMonthDate('1992-10-10'); // Output will be 'Thu Sep 10 1992 05:30:00 GMT+0530 (India Standard Time)'
    getPreviousMonthDate(new Date()); // Output will be 'Tue Jan 04 2022 02:28:43 GMT+0530 (India Standard Time)'
    getPreviousMonthDate('03/25/2015'); // Output will be 'Wed Feb 25 2015 00:00:00 GMT+0530 (India Standard Time)'
    getPreviousMonthDate(); // Output will be 'Invalid date'
    getPreviousMonthDate('03/31/2022'); // Output will be 'Thu Mar 03 2022 00:00:00 GMT+0530 (India Standard Time)'
    getPreviousMonthDate(new Date(), 10); // Output will be 'Sun Apr 04 2021 15:18:48 GMT+0530 (India Standard Time)'. new Date() creates a
    new instance of date and returns the current date. When this function was written current date was 4th Apr so output is that. If you write
    it now date will be different.

    Parameters

    • date: Date

      Date in valid Date format

    • monthCount: number = 1

      Number of months we want to go back to

    Returns undefined | Date

  • getReportDateInput(lastSupportedYear: number, offsetFromCurrentFinancialYear?: number): { endDate: string; startDate: string }[]
  • This function returns an array of objects which specify financial years from last supported year to offset year from current financial year.

    remarks

    This function returns a list of UI data to be returned from a start year to end year (financial year data). lastSupportedyear is the start year, and the end year is current year or if any offset is there, then end year is current year minus offset. This function helps in showing a dropdown of all available financial years to choose from. Mainly used in Reports section of the website.

    example
    getReportDateInput(2020, 1);  // Output will be [{startDate: 'Apr 2020', endDate: 'Mar 2021'}]
    getReportDateInput(2020); // Output will be [{startDate: 'Apr 2021', endDate: 'Mar 2022'}, {startDate: 'Apr 2020', endDate: 'Mar 2021'}]

    Parameters

    • lastSupportedYear: number

      last year in number from which array of values needs to be returned

    • offsetFromCurrentFinancialYear: number = 0

      offset from current year of the year upto which the values have to be returned

    Returns { endDate: string; startDate: string }[]

  • isAgeMinor(dob: string): boolean
  • This method Checks whether Age is less than 18 or not.

    example
    isAgeMinor('10/10/1995');  // Output will be false
    isAgeMinor('10/10/2020'); // Output will be true

    Parameters

    • dob: string

      string entered in input element (ddmmyyyy or dd/mm/yyyy)

    Returns boolean

  • isValidDate(dateStr: string, delimiter?: string): boolean
  • This function checks if input date is valid or not in this format 'YYYY-MM-DD'. We can also validate dates in this format also 'YYYY/MM/DD' if we send '/' as 2nd parameter, or basically anything as delimiter(2nd paramter).

    remarks

    One other way to check valid date is new Date(inputDate) but a limitation is leap year date in those. Example: new Date('2022-2-29'); returns 'Tue Mar 01 2022 00:00:00 GMT+0530 (India Standard Time)' although this should not be a valid date. This function returns false in such cases.

    example
    isValidDate();  // Output is false
    isValidDate('1993-10-10'); // Output is true
    isValidDate('1993/10/10'); // Output is false
    isValidDate('1993/10/10', '/'); // Output is true
    isValidDate('10/10/1993', '/'); // Output is false
    isValidDate('1907-10-10'); // Output is true
    isValidDate('1707-10-10'); // Output is true
    isValidDate('1000-10-10'); // Output is true
    isValidDate('1-1-1'); // Output is true
    isValidDate('1707-10-32); // Output is false
    isValidDate('2022-2-29'); // Output is false as 2022 is not a leap year
    isValidDate('2020-2-29'); // Output is true as 2020 was a leap year

    Parameters

    • dateStr: string
    • delimiter: string = '-'

      Provide delimiter in case date uses other delimiter than '-'.

      • eg. Pass '/' in case date is in format of YYYY/MM/DD

    Returns boolean

Generated using TypeDoc