2014-03-03 09:44:32 +01:00
|
|
|
/**
|
|
|
|
*
|
2021-05-02 17:14:15 +02:00
|
|
|
* Copyright 2014-2021 Florian Schmaus
|
2014-03-03 09:44:32 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.time.packet;
|
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2014-03-03 09:44:32 +01:00
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.TimeZone;
|
|
|
|
|
2021-05-02 17:14:15 +02:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2020-04-12 09:34:08 +02:00
|
|
|
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2014-03-03 09:44:32 +01:00
|
|
|
|
2020-04-12 09:34:08 +02:00
|
|
|
public class TimeTest extends SmackTestSuite {
|
2014-03-03 09:44:32 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void parseCurrentTimeTest() {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
2021-05-02 17:14:15 +02:00
|
|
|
Time time = Time.builder("dummy")
|
|
|
|
.ofType(IQ.Type.result)
|
|
|
|
.setTime(calendar)
|
|
|
|
.build();
|
2014-03-03 09:44:32 +01:00
|
|
|
|
|
|
|
Date date = time.getTime();
|
|
|
|
Date calendarDate = calendar.getTime();
|
|
|
|
|
|
|
|
assertEquals(calendarDate, date);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void negativeTimezoneTest() {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.setTimeZone(TimeZone.getTimeZone("GMT-830"));
|
2021-05-02 17:14:15 +02:00
|
|
|
Time time = Time.builder("dummy")
|
|
|
|
.ofType(IQ.Type.result)
|
|
|
|
.setTime(calendar)
|
|
|
|
.build();
|
2014-03-03 09:44:32 +01:00
|
|
|
|
|
|
|
assertEquals("-8:30", time.getTzo());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void positiveTimezoneTest() {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
calendar.setTimeZone(TimeZone.getTimeZone("GMT+830"));
|
2021-05-02 17:14:15 +02:00
|
|
|
Time time = Time.builder("dummy")
|
|
|
|
.ofType(IQ.Type.result)
|
|
|
|
.setTime(calendar)
|
|
|
|
.build();
|
2014-03-03 09:44:32 +01:00
|
|
|
|
|
|
|
assertEquals("+8:30", time.getTzo());
|
|
|
|
}
|
|
|
|
}
|