package com.red.circle.common.business.core.date;

import com.red.circle.tool.core.date.DateFormatConstant;
import com.red.circle.tool.core.date.ZonedId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 上海时区.
 *
 * @author pengliang on 2023/8/25
 */
public interface AsiaShanghaiDateUtils {

  /**
   * 当前日期数值.
   */
  static Integer nowDateToInt() {
    return Integer.valueOf(nowFormat(DateFormatConstant.yyyyMMdd));
  }

  /**
   * 当前日期数值， 减去指定天.
   */
  static Integer nowMinusDateToInt(long days) {
    return Integer.valueOf(format(now().minusDays(days), DateFormatConstant.yyyyMMdd));
  }

  /**
   * 当前日期数值， 加上指定天.
   */
  static Integer nowPlusDateToInt(long days) {
    return Integer.valueOf(format(now().plusDays(days), DateFormatConstant.yyyyMMdd));
  }

  /**
   * 当前月转Int.
   */
  static Integer nowMonthToInt() {
    return Integer.valueOf(nowFormat(DateFormatConstant.yyyyMM));
  }

  /**
   * 格式化输出当前时间.
   */
  static String nowFormat(String formatPattern) {
    return now().format(DateTimeFormatter.ofPattern(formatPattern));
  }

  /**
   * 格式化.
   */
  public static String format(ZonedDateTime time, String formatPattern) {
    return time.format(DateTimeFormatter.ofPattern(formatPattern));
  }

  /**
   * 当前时间.
   */
  static ZonedDateTime now() {
    return ZonedDateTime.now(ZonedId.ASIA_RIYADH.getZonedId());
  }

}
