本文整理汇总了Java中org.threeten.bp.OffsetDateTime.of方法的典型用法代码示例。如果您正苦于以下问题:Java OffsetDateTime.of方法的具体用法?Java OffsetDateTime.of怎么用?Java OffsetDateTime.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.OffsetDateTime
的用法示例。
在下文中一共展示了OffsetDateTime.of方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchLibrariesFromApiAndSaveThem
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
@Test
public void fetchLibrariesFromApiAndSaveThem() {
OffsetDateTime lastUpdated = OffsetDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
when(libraryService.lastUpdated()).thenReturn(Observable.just(lastUpdated));
List<Library> newLibraries = Collections.singletonList(MockLibrary.TEST);
when(disclosureApi.allLibraries(any(), anyInt(), anyInt()))
.thenReturn(Observable.just(newLibraries))
.thenReturn(Observable.just(new ArrayList<>()));
TestSubscriber<List<Library>> testSubscriber = new TestSubscriber<>();
syncLibraries.run()
.toBlocking()
.subscribe(testSubscriber);
verify(disclosureApi).allLibraries(lastUpdated, 1, 50);
verify(libraryService).insertOrUpdate(newLibraries);
testSubscriber.assertReceivedOnNext(Collections.singletonList(newLibraries));
testSubscriber.assertNoErrors();
testSubscriber.assertCompleted();
}
示例2: callOnErrorIfApiReturnsAnError
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
@Test
public void callOnErrorIfApiReturnsAnError() {
OffsetDateTime lastUpdated = OffsetDateTime.of(2016, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
when(libraryService.lastUpdated()).thenReturn(Observable.just(lastUpdated));
Throwable apiError = new Throwable();
when(disclosureApi.allLibraries(any(), anyInt(), anyInt())).thenReturn(
Observable.error(apiError));
TestSubscriber<List<Library>> testSubscriber = new TestSubscriber<>();
syncLibraries.run()
.toBlocking()
.subscribe(testSubscriber);
testSubscriber.assertError(apiError);
}
示例3: testSerialisation
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
/**
* Tests that serialising to JSON works.
*/
@Test
public void testSerialisation() throws Exception
{
final Gson gson = Converters.registerAll(new GsonBuilder()).create();
final Container container = new Container();
container.ld = LocalDate.of(1969, 7, 21);
container.lt = LocalTime.of(12, 56, 0);
container.ldt = LocalDateTime.of(container.ld, container.lt);
container.odt = OffsetDateTime.of(container.ld, container.lt, ZoneOffset.ofHours(10));
container.ot = OffsetTime.of(container.lt, ZoneOffset.ofHours(10));
container.zdt = ZonedDateTime.of(container.ld, container.lt, ZoneId.of("Australia/Brisbane"));
container.i = container.odt.toInstant();
final String jsonString = gson.toJson(container);
final JsonObject json = gson.fromJson(jsonString, JsonObject.class).getAsJsonObject();
assertThat(json.get("ld").getAsString(), is("1969-07-21"));
assertThat(json.get("lt").getAsString(), is("12:56:00"));
assertThat(json.get("ldt").getAsString(), is("1969-07-21T12:56:00"));
assertThat(json.get("odt").getAsString(), is("1969-07-21T12:56:00+10:00"));
assertThat(json.get("ot").getAsString(), is("12:56:00+10:00"));
assertThat(json.get("zdt").getAsString(), is("1969-07-21T12:56:00+10:00[Australia/Brisbane]"));
assertThat(json.get("i").getAsString(), is("1969-07-21T02:56:00Z"));
}
示例4: deserialize
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
@Override
public OffsetDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String src = json.getAsString();
// TODO 有些时间结构不符合标准,这里做兼容
try {
return OffsetDateTime.parse(src);
} catch (DateTimeParseException e) {
return OffsetDateTime.of(LocalDateTime.parse(src, formatterCompat), ZoneOffset.UTC);
}
}
示例5: serializeDateToJson
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
@Test public void serializeDateToJson() {
OffsetDateTime testDate = OffsetDateTime.of(2016, 1, 1, 12, 0, 30, 0, ZoneOffset.UTC);
String expectedDate = "2016-01-01T12:00:30Z";
JsonElement jsonDate = adapter.serialize(testDate, OffsetDateTime.class, serializationContext);
assertThat(jsonDate.getAsString()).isEqualTo(expectedDate);
}
示例6: deserializeJsonToDate
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
@Test public void deserializeJsonToDate() {
String testJson = "2016-01-01T01:30:15Z";
JsonElement json = new JsonPrimitive(testJson);
OffsetDateTime expectedDate = OffsetDateTime.of(2016, 1, 1, 1, 30, 15, 0, ZoneOffset.UTC);
OffsetDateTime date = adapter.deserialize(json, OffsetDateTime.class, deserializationContext);
assertThat(date).isEqualTo(expectedDate);
}
示例7: testDeserialisation
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
/**
* Tests that deserialising from JSON works.
*/
@Test
public void testDeserialisation() throws Exception
{
final Gson gson = Converters.registerAll(new GsonBuilder()).create();
final Container container = new Container();
container.ld = LocalDate.of(1969, 7, 21);
container.lt = LocalTime.of(12, 56, 0);
container.ldt = LocalDateTime.of(container.ld, container.lt);
container.odt = OffsetDateTime.of(container.ld, container.lt, ZoneOffset.ofHours(10));
container.ot = OffsetTime.of(container.lt, ZoneOffset.ofHours(10));
container.zdt = ZonedDateTime.of(container.ld, container.lt, ZoneId.of("Australia/Brisbane"));
container.i = container.odt.toInstant();
final JsonObject serialized = new JsonObject();
serialized.add("ld", new JsonPrimitive("1969-07-21"));
serialized.add("lt", new JsonPrimitive("12:56:00"));
serialized.add("ldt", new JsonPrimitive("1969-07-21T12:56:00"));
serialized.add("odt", new JsonPrimitive("1969-07-21T12:56:00+10:00"));
serialized.add("ot", new JsonPrimitive("12:56:00+10:00"));
serialized.add("zdt", new JsonPrimitive("1969-07-21T12:56:00+10:00[Australia/Brisbane]"));
serialized.add("i", new JsonPrimitive("1969-07-21T02:56:00Z"));
final String jsonString = gson.toJson(serialized);
final Container deserialised = gson.fromJson(jsonString, Container.class);
assertThat(deserialised.ld, is(container.ld));
assertThat(deserialised.ldt, is(container.ldt));
assertThat(deserialised.lt, is(container.lt));
assertThat(deserialised.odt, is(container.odt));
assertThat(deserialised.ot, is(container.ot));
assertThat(deserialised.zdt, is(container.zdt));
assertThat(deserialised.i, is(container.i));
}
示例8: instantToTaiMillisSince2004Mod32
import org.threeten.bp.OffsetDateTime; //导入方法依赖的package包/类
/** Returns TAI milliseconds mod 2^32 for the given date.
*
* Since java int is signed 32 bit integer, return long instead.
* It is the same on byte level, but just to avoid confusing people with negative values here.
*
*
* From http://stjarnhimlen.se/comp/time.html:
*
* TAI (Temps Atomique International or International Atomic Time) is
* defined as the weighted average of the time kept by about 200
* atomic clocks in over 50 national laboratories worldwide.
* TAI-UT1 was approximately 0 on 1958 Jan 1.
* (TAI is ahead of UTC by 35 seconds as of 2014.)
*
* GPS time = TAI - 19 seconds. GPS time matched UTC from 1980-01-01
* to 1981-07-01. No leap seconds are inserted into GPS time, thus
* GPS time is 13 seconds ahead of UTC on 2000-01-01. The GPS epoch
* is 00:00 (midnight) UTC on 1980-01-06.
* The difference between GPS Time and UTC changes in increments of
* seconds each time a leap second is added to UTC time scale.
*/
public static long instantToTaiMillisSince2004Mod32(Instant instantX) {
OffsetDateTime gnEpochStart =
OffsetDateTime.of(LocalDateTime.of(2004, Month.JANUARY, 1, 0, 0), ZoneOffset.UTC);
long millis2004 = gnEpochStart.toInstant().toEpochMilli();
long millisAtX = instantX.toEpochMilli();
long taiMillis = (millisAtX + LEAP_SECONDS_SINCE_2004*1000) - millis2004;
return taiMillis % (1L << 32);
}