package com.pingcap.community.blogserver.util;

import lombok.extern.slf4j.Slf4j;

import java.time.*;
import java.util.Date;

@Slf4j
public class TimeUtils {

  private static final ZoneId zoneOffset = ZoneId.of("Asia/Shanghai");

  public static Date getTodayStartTimeWithoutOffset() {
    ZonedDateTime instant = ZonedDateTime.now(zoneOffset).withHour(0).withMinute(0).withSecond(0);
    ZonedDateTime instantInUTC = instant.withZoneSameInstant(ZoneId.of("UTC"));
    return Date.from(instantInUTC.toInstant());
  }

  public static Date getTodayEndTimeWithoutOffset() {
    ZonedDateTime instant = ZonedDateTime.now(zoneOffset).withHour(23).withMinute(59).withSecond(59);
    ZonedDateTime instantInUTC = instant.withZoneSameInstant(ZoneId.of("UTC"));
    return Date.from(instantInUTC.toInstant());
  }

  public static Date getCurrentYearStartTimeWithoutOffset() {
    ZonedDateTime instant = ZonedDateTime.now(zoneOffset).withMonth(1).withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
    ZonedDateTime instantInUTC = instant.withZoneSameInstant(ZoneId.of("UTC"));
    return Date.from(instantInUTC.toInstant());
  }

  public static Date getCurrentYearEndTimeoutWithOffset() {
    ZonedDateTime instant = ZonedDateTime.now(zoneOffset).withMonth(12).withDayOfMonth(31).withHour(23).withMinute(59).withSecond(59);
    ZonedDateTime instantInUTC = instant.withZoneSameInstant(ZoneId.of("UTC"));
    return Date.from(instantInUTC.toInstant());
  }

}
