package com.atlassian.stash.internal.web.timezone;

import org.junit.Test;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;

import static org.junit.Assert.assertEquals;

public class TimeZoneOffsetHelperTest {

    @Test
    public void offsetInMinutes() {
        ZoneId id = ZoneId.of("Australia/Sydney");
        assertEquals(-600, TimeZoneOffsetHelper.toGmtDifferenceInMinutes(id, Instant.now()));
        assertEquals(-600, TimeZoneOffsetHelper.toGmtDifferenceInMinutes(id, Instant.ofEpochMilli(100051454)));

        Instant now = Instant.now();
        LocalDateTime gmtTime = LocalDateTime.ofInstant(now, ZoneId.of("GMT"));
        LocalDateTime sydneyTime = LocalDateTime.ofInstant(now, id);
        assertEquals(gmtTime, sydneyTime.plus(TimeZoneOffsetHelper.toGmtDifferenceInMinutes(id, now), ChronoUnit.MINUTES));
    }
}