package com.ruoyi.web.modules.trading.support;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 牦牛行情日期换算与展示标签。
 */
public final class YakMarketDateSupport
{
    private static final ZoneId ZONE = ZoneId.systemDefault();

    private static final DateTimeFormatter CHART_LABEL = DateTimeFormatter.ofPattern("MM-dd");

    private YakMarketDateSupport()
    {
    }

    public static LocalDate yesterday()
    {
        return LocalDate.now(ZONE).minusDays(1);
    }

    public static Date toSqlDate(LocalDate day)
    {
        return Date.from(day.atStartOfDay(ZONE).toInstant());
    }

    public static String chartDateLabel(Date quoteDate)
    {
        if (quoteDate == null)
        {
            return "";
        }
        LocalDate d = quoteDate.toInstant().atZone(ZONE).toLocalDate();
        return CHART_LABEL.format(d);
    }

    private static final DateTimeFormatter SHORT_MD = DateTimeFormatter.ofPattern("MM-dd");

    public static String shortMonthDayLabel(Date quoteDate)
    {
        if (quoteDate == null)
        {
            return "";
        }
        LocalDate d = quoteDate.toInstant().atZone(ZONE).toLocalDate();
        return SHORT_MD.format(d);
    }
}
