package com.base.filerecoveryrecyclebin.utils

import java.util.Calendar

object TimeUtils {

    fun isWithinOneMonth(pastTimestamp: Long): Boolean {
        val calendar = Calendar.getInstance()
        val currentTime = System.currentTimeMillis()

        // 将当前时间减去一个月
        calendar.timeInMillis = currentTime
        calendar.add(Calendar.MONTH, -1)
        val oneMonthAgo = calendar.timeInMillis

        // 检查过去的时间戳是否在当前时间与一个月前之间
        return pastTimestamp in oneMonthAgo..currentTime
    }

    fun isWithinSixMonths(pastTimestamp: Long): Boolean {
        val calendar = Calendar.getInstance() // 获取当前时间的Calendar实例
        val currentTime = System.currentTimeMillis() // 获取当前时间的时间戳

        // 设置calendar到当前时间
        calendar.timeInMillis = currentTime
        // 减去6个月
        calendar.add(Calendar.MONTH, -6)

        val sixMonthsAgo = calendar.timeInMillis // 计算6个月前的日期

        // 检查过去的时间戳是否在6个月的范围内
        return pastTimestamp in sixMonthsAgo..currentTime
    }

    fun isWithinTwentyFourMonths(timestamp: Long): Boolean {
        val calendar = Calendar.getInstance() // 获取当前时间的Calendar实例
        val currentTime = System.currentTimeMillis() // 获取当前时间的时间戳

        // 设置calendar到当前时间
        calendar.timeInMillis = currentTime
        // 减去24个月
        calendar.add(Calendar.MONTH, -24)

        val twentyFourMonthsAgo = calendar.timeInMillis // 计算24个月前的日期

        // 检查时间戳是否在24个月的范围内
        return timestamp in twentyFourMonthsAgo..currentTime
    }
}