package com.zfire.mall.manager.bean.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

public class NotBeforeTodayValidator implements ConstraintValidator<NotBeforeToday, Date> {

    @Override
    public boolean isValid(Date value, ConstraintValidatorContext context) {
        if (value == null) {
            return true; // 允许为空
        }
        // 转换为系统默认时区的当天日期
        LocalDate inputDate = value.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalDate();
        LocalDate today = LocalDate.now();
        return !inputDate.isBefore(today);
    }
}
