package com.caliverse.admin.global.common.utils;

import com.caliverse.admin.global.common.constants.CommonConstants;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class DateUtils {
    public static String stringToDateTime(LocalDateTime date) {
        if(date == null) return null;
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(CommonConstants.FORMAT_DATE_DATETIME);
        return date.format(formatter);
    }

    public static String stringToISODateTime(LocalDateTime date){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(CommonConstants.FORMAT_DATE_ISO_DATETIME);
        return date.atOffset(ZoneOffset.UTC).format(formatter);
    }

    public static String stringToISODateTimeMillis(LocalDateTime date){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(CommonConstants.FORMAT_DATE_ISO_DATETIME_MILLIS);
        return date.atOffset(ZoneOffset.UTC).format(formatter);
    }

    public static String nowDateTime(){
        LocalDateTime now = LocalDateTime.now();
        return stringToDateTime(now);
    }

    public static String getDynamodbDateFormat(LocalDateTime date){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS");
        return date.format(formatter);
    }
}
