package Gson;

import java.time.format.DateTimeFormatter;

public class DateTimeHelper {

    private static final DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    private static final DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMdd");

    /**
     * Check if the date is valid in the format yyyy-MM-dd
     * @param date the date to check
     * @return true if the date is valid, false otherwise
     */
    public static boolean isValidDate_yyyyMMdd(String date) {
        try {
            dtf1.parse(date);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public static String ConvertToTableName(String date) {
        return dtf2.format(dtf1.parse(date));
    }
}
