import moment from "moment";

export class FormatterUtils {
    static formatTime(timeString: string): string {
        if (timeString === null || timeString === '') {
            return ''
        }
        try {
            return moment(timeString).format('yyyy-MM-DD HH:mm:ss')
        }catch {
            return timeString
        }
    }

    static formatCellValueTime(row:any, column:any, cellValue:any) {
        if (cellValue === null || cellValue === '') {
            return ''
        }
        try {
            return moment(cellValue).format('yyyy-MM-DD HH:mm:ss')
        }catch {
            return cellValue
        }
    }

    static formatterStringToJson(json: string | undefined) {
        if (json == undefined || json.trim() === '') {
            return ''
        }
        try {
            return JSON.parse(json)
        } catch (error) {
            return json
        }
    }
}