package com.orionplatform.calendar.conversion.tasks.sqldate;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import com.orionplatform.calendar.date.Date;
import com.orionplatform.calendar.date.DateRules;
import com.orionplatform.calendar.datetime.DateTime;
import com.orionplatform.core.abstraction.Orion;

public class ConvertSQLDateToDateTimeObjectTask extends Orion
{
    public static synchronized DateTime run(String SQLDate)
    {
        DateRules.isValidSQLDate(SQLDate);
        
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
        LocalDate localDate = LocalDate.parse(SQLDate, formatter);
        Date date = Date.of(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth());
        return DateTime.of(date);
    }


    public static synchronized DateTime run(java.sql.Date SQLDate)
    {
        DateRules.isValidSQLDate(SQLDate);
        Date date = Date.of(SQLDate.getYear(), SQLDate.getMonth() + 1, SQLDate.getDate());
        return DateTime.of(date);
    }
}