package com.bonus.common.core.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Pattern;

/**
 * @className:TimeValidator
 * @author:cwchen
 * @date:2024-08-10-15:15
 * @version:1.0
 * @description:时间验证
 */
public class TimeValidator {

    private static final Pattern TIME_PATTERN = Pattern.compile("^([01]?[0-9]|2[0-3]):[0-5][0-9]$");
    private static final Pattern TIME_PATTERN2 = Pattern.compile("^[1-9]$|^10$");

    /**
     * 时分校验
     * @param time
     * @return boolean
     * @author cwchen
     * @date 2024/8/10 15:16
     */
    public static boolean isValidTime(String time) {
        if (StringUtils.isEmpty(time)) {
            return false;
        }
        return TIME_PATTERN.matcher(time).matches();
    }

    /**
     * 1-10 小时验证
     * @param time
     * @return boolean
     * @author cwchen
     * @date 2024/8/10 15:20
     */
    public static boolean isValidTime2(String time) {
        if (StringUtils.isEmpty(time)) {
            return false;
        }
        return TIME_PATTERN2.matcher(time).matches();
    }

}
