package cn.com.victorysoft.business.calc.param;

import cn.com.victorysoft.business.util.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.SneakyThrows;

import java.util.Calendar;
import java.util.Date;

@Data
@ApiModel("实时数据班次")
public class RealtimeRange {
    @ApiModelProperty("日期")
    private Date date;
    @ApiModelProperty("班次时间，08:00")
    private String time;

    @SneakyThrows
    public Date parseDate() {
        return DateUtils.parseDate(DateUtils.formatDate(date) + " " + time, "yyyy-MM-dd HH:mm");
    }

    public static RealtimeRange getFromDate(Date dateTime) {
        Date date = DateUtils.truncate(dateTime, Calendar.DATE);
        String time = DateUtils.format(dateTime, "HH:mm");
        RealtimeRange range = new RealtimeRange();
        range.setDate(date);
        range.setTime(time);
        return range;
    }
}
