package com.jay.monitor.data.server.factory.generate;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Module TODO
 * @Description TODO
 * @Author liukaixiong
 * @Date 2020/11/9 13:48
 */
public class HourIdGenerateTest {
    SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");

    @Test
    public void getHourTimestamp() {
        long timestamp = System.currentTimeMillis();
        getTimestamp(timestamp);

        timestamp = 1604901600000L;
        getTimestamp(timestamp);
    }

    private long getTimestamp(long timestamp) {
        long HOUR = 3600 * 1000L;
        long hour = timestamp / HOUR;
        System.out.println(hour);
        return hour;
    }

    @Test
    public void testTimeStrap() {

        // 1109
//        Long startTime = 1604880000000L;
//        Long startTime = 1604937599000L;
        Long startTime = 1604851199000L;
        long timestrap = getTimestrap(startTime);

        startTime = 1604851200000L;
        timestrap = getTimestrap(startTime);

        // 1110
        startTime = 1604937600000L;
        timestrap = getTimestrap(startTime);

        startTime = System.currentTimeMillis();
        timestrap = getTimestrap(startTime);

    }

    private long getTimestrap(Long startTime) {
        Long add = 8 * 3600 * 1000L;
        System.out.println("day : " + add);
        startTime = startTime + add;
        long DAY = 24 * 60 * 60 * 1000L;
        long value = startTime / DAY;
        Date date = new Date(startTime);
        System.out.println(sfd.format(date) + "\t" + value);
        return value;
    }
}