本文整理汇总了Java中org.threeten.bp.OffsetDateTime类的典型用法代码示例。如果您正苦于以下问题:Java OffsetDateTime类的具体用法?Java OffsetDateTime怎么用?Java OffsetDateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OffsetDateTime类属于org.threeten.bp包,在下文中一共展示了OffsetDateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRelativeTimeSpanString
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
public static String getRelativeTimeSpanString(@NonNull OffsetDateTime offsetDateTime) {
long offset = Duration.between(offsetDateTime, OffsetDateTime.now()).toMillis();
if (offset > YEAR) {
return (offset / YEAR) + "年前";
} else if (offset > MONTH) {
return (offset / MONTH) + "个月前";
} else if (offset > WEEK) {
return (offset / WEEK) + "周前";
} else if (offset > DAY) {
return (offset / DAY) + "天前";
} else if (offset > HOUR) {
return (offset / HOUR) + "小时前";
} else if (offset > MINUTE) {
return (offset / MINUTE) + "分钟前";
} else {
return "刚刚";
}
}
示例2: run
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
public Observable<Library> run(String title, String packageName, String websiteUrl,
Library.Type type) {
return Observable.fromCallable(() -> {
String sourceDir = packageName.replace(".", "/");
return Library.builder()
.id(UUID.randomUUID().toString())
.title(title)
.subtitle("")
.description("")
.packageName(packageName)
.sourceDir(sourceDir)
.websiteUrl(websiteUrl)
.createdAt(OffsetDateTime.now())
.updatedAt(OffsetDateTime.now())
.type(type)
.build();
}).doOnNext(library -> libraryService.insert(Collections.singletonList(library)));
}
示例3: 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();
}
示例4: 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);
}
示例5: parameterToString
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
/**
* Format the given parameter object into string.
*
* @param param Parameter
* @return String representation of the parameter
*/
public String parameterToString(Object param) {
if (param == null) {
return "";
} else if (param instanceof Date || param instanceof OffsetDateTime || param instanceof LocalDate) {
//Serialize to json string and remove the " enclosing characters
String jsonStr = json.serialize(param);
return jsonStr.substring(1, jsonStr.length() - 1);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for (Object o : (Collection)param) {
if (b.length() > 0) {
b.append(",");
}
b.append(String.valueOf(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
}
示例6: test_addWithTwoTrades_addThenGet
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
@Test
public void test_addWithTwoTrades_addThenGet() {
ManageablePosition position = new ManageablePosition(BigDecimal.valueOf(20), ExternalId.of("A", "B"));
OffsetDateTime offsetDateTime = OffsetDateTime.now();
position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(600).toOffsetTime(), ExternalId.of("CPS", "CPV")));
position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "C"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(500).toOffsetTime(), ExternalId.of("CPS", "CPV")));
PositionDocument doc = new PositionDocument();
doc.setPosition(position);
PositionDocument added = _posMaster.add(doc);
assertNotNull(added);
assertNotNull(added.getUniqueId());
PositionDocument fromDb = _posMaster.get(added.getUniqueId());
assertNotNull(fromDb);
assertNotNull(fromDb.getUniqueId());
assertEquals(added, fromDb);
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:ModifyPositionDbPositionMasterWorkerAddPositionTest.java
示例7: run
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
@Override
public void run() {
for (Map.Entry<LiveDataSpecification, FudgeMsg> entry : _allValues.entrySet()) {
OffsetDateTime atTheHour = OffsetDateTime.now(Clock.systemUTC()).truncatedTo(MINUTES);
if (atTheHour.getMinute() >= 55) {
// Assume we got triggered early.
atTheHour = atTheHour.withMinute(0).plusHours(1);
} else {
atTheHour = atTheHour.withMinute(0);
}
String observationTimeName = atTheHour.toOffsetTime().toString();
try {
_storageExecutor.execute(new StorageTask(entry.getKey(), entry.getValue(), atTheHour.toLocalDate(), observationTimeName));
} catch (Exception e) {
s_logger.error("Unable to submit a storage task to store {} {}", entry.getKey(), entry.getValue());
}
}
}
示例8: setUp
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
@BeforeMethod
public void setUp(Method m) throws Exception {
MockReferenceDataProvider refDataProvider = new MockReferenceDataProvider();
refDataProvider.addExpectedField("SECURITY_TYP");
refDataProvider.addResult("QQQQ US Equity", "SECURITY_TYP", "ETP");
refDataProvider.addResult("/buid/EQ0082335400001000", "SECURITY_TYP", "ETP");
File watchListFile = new File(BloombergRefDataCollectorTest.class.getResource(WATCH_LIST_FILE).toURI());
File fieldListFile = new File(BloombergRefDataCollectorTest.class.getResource(FIELD_LIST_FILE).toURI());
String outfileName = getClass().getSimpleName() + "-" + Thread.currentThread().getName() +
"-" + OffsetDateTime.now(ZoneOffset.UTC).toString(DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'"));
_outputFile = File.createTempFile(outfileName, null);
_outputFile.deleteOnExit();
_refDataCollector = new BloombergRefDataCollector(s_fudgeContext, watchListFile, refDataProvider, fieldListFile, _outputFile);
_refDataCollector.start();
}
示例9: test_resolve_trade
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
public void test_resolve_trade() {
final OffsetDateTime now = OffsetDateTime.now();
final InMemorySecuritySource secSource = new InMemorySecuritySource();
final MockPositionSource posSource = new MockPositionSource();
final SimplePortfolio portfolio = new SimplePortfolio(UniqueId.of("Test", "1"), "Name");
final SimplePosition position = new SimplePosition(UniqueId.of("Test", "1"), new BigDecimal(1), ExternalIdBundle.EMPTY);
final SimpleTrade trade = new SimpleTrade(new SimpleSecurityLink(), new BigDecimal(1), new SimpleCounterparty(ExternalId.of("CPARTY", "C100")), now.toLocalDate(), now.toOffsetTime());
trade.setUniqueId(UniqueId.of("TradeScheme", "1"));
position.addTrade(trade);
portfolio.getRootNode().addPosition(position);
posSource.addPortfolio(portfolio);
final DefaultComputationTargetResolver test = new DefaultComputationTargetResolver(secSource, posSource);
final ComputationTargetSpecification spec = ComputationTargetSpecification.of(trade);
final ComputationTarget expected = new ComputationTarget(ComputationTargetType.TRADE, trade);
assertExpected(expected, test.resolve(spec, VersionCorrection.LATEST));
}
示例10: 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"));
}
示例11: 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);
}
}
示例12: install
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
private void install()
{
SharedPreferences sharedPreferences= PreferenceManager.getDefaultSharedPreferences(this);
boolean ifinstall=sharedPreferences.getBoolean("ifinstall",false);
if (!ifinstall)
{
//实例化Editor对象
SharedPreferences.Editor editor = sharedPreferences.edit();
//存入数据
editor.putBoolean("ifinstall",true);//已安装
//默认值
editor.putBoolean("notifications_enabled",true);
editor.putBoolean("notifications_vibrate_enabled",true);
LocalDateTime now=LocalDateTime.now();
now=LocalDateTime.of(now.getYear(),now.getMonth(),now.getDayOfMonth(),12,0);
ZoneOffset zoneOffset = OffsetDateTime.now(ZoneId.systemDefault()).getOffset ();
editor.putLong("notifications_time",now.toEpochSecond(zoneOffset)*1000);//当地12点的格林尼治时间戳
//Log.w("Time1",String.valueOf(now.toEpochSecond(zoneOffset)*1000));
//Log.w("Time1",String.valueOf(now.toEpochSecond(ZoneOffset.UTC)*1000));
editor.putString("notifications_ringtone","content://settings/system/notification_sound");
editor.putString("calendar_first_day_of_week","0");
//提交修改
editor.commit();
}
}
示例13: lastUpdated
import org.threeten.bp.OffsetDateTime; //导入依赖的package包/类
public Observable<OffsetDateTime> lastUpdated(BriteDatabase db) {
SqlDelightStatement selectLastUpdated = Library.FACTORY.selectLastUpdated();
return db.createQuery(selectLastUpdated.tables, selectLastUpdated.statement)
.map(SqlBrite.Query::run)
.map(cursor -> {
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
return Library.FACTORY.selectLastUpdatedMapper().map(cursor);
}
return Date.MIN;
});
}
示例14: 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);
}
示例15: 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);
}