当前位置: 首页>>代码示例>>Java>>正文


Java ZoneId类代码示例

本文整理汇总了Java中org.threeten.bp.ZoneId的典型用法代码示例。如果您正苦于以下问题:Java ZoneId类的具体用法?Java ZoneId怎么用?Java ZoneId使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ZoneId类属于org.threeten.bp包,在下文中一共展示了ZoneId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchHistoryOfChannel

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
    Map<String, String> params = new HashMap<>();
    params.put("channel", channelId);
    if (day != null) {
        ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
        ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
        params.put("oldest", convertDateToSlackTimestamp(start));
        params.put("latest", convertDateToSlackTimestamp(end));
    }
    if (numberOfMessages > -1) {
        params.put("count", String.valueOf(numberOfMessages));
    } else {
        params.put("count", String.valueOf(DEFAULT_HISTORY_FETCH_SIZE));
    }
    SlackChannel channel =session.findChannelById(channelId);
    switch (channel.getType()) {
        case INSTANT_MESSAGING:
            return fetchHistoryOfChannel(params,FETCH_IM_HISTORY_COMMAND);
        case PRIVATE_GROUP:
            return fetchHistoryOfChannel(params,FETCH_GROUP_HISTORY_COMMAND);
        default:
            return fetchHistoryOfChannel(params,FETCH_CHANNEL_HISTORY_COMMAND);
    }
}
 
开发者ID:riversun,项目名称:slacklet,代码行数:26,代码来源:ChannelHistoryModuleImpl.java

示例2: CustomInstantDeserializer

import org.threeten.bp.ZoneId; //导入依赖的package包/类
protected CustomInstantDeserializer(Class<T> supportedType,
                  DateTimeFormatter parser,
                  Function<TemporalAccessor, T> parsedToValue,
                  Function<FromIntegerArguments, T> fromMilliseconds,
                  Function<FromDecimalArguments, T> fromNanoseconds,
                  BiFunction<T, ZoneId, T> adjust) {
  super(supportedType, parser);
  this.parsedToValue = parsedToValue;
  this.fromMilliseconds = fromMilliseconds;
  this.fromNanoseconds = fromNanoseconds;
  this.adjust = adjust == null ? new BiFunction<T, ZoneId, T>() {
    @Override
    public T apply(T t, ZoneId zoneId) {
      return t;
    }
  } : adjust;
}
 
开发者ID:cliffano,项目名称:swaggy-jenkins,代码行数:18,代码来源:CustomInstantDeserializer.java

示例3: fetchHistoryOfChannel

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@Override
public List<SlackMessagePosted> fetchHistoryOfChannel(String channelId, LocalDate day, int numberOfMessages) {
    Map<String, String> params = new HashMap<>();
    params.put("channel", channelId);
    if (day != null) {
        ZonedDateTime start = ZonedDateTime.of(day.atStartOfDay(), ZoneId.of("UTC"));
        ZonedDateTime end = ZonedDateTime.of(day.atStartOfDay().plusDays(1).minus(1, ChronoUnit.MILLIS), ZoneId.of("UTC"));
        params.put("oldest", convertDateToSlackTimestamp(start));
        params.put("latest", convertDateToSlackTimestamp(end));
    }
    if (numberOfMessages > -1) {
        params.put("count", String.valueOf(numberOfMessages));
    } else {
        params.put("count", String.valueOf(1000));
    }
    return fetchHistoryOfChannel(params);
}
 
开发者ID:JujaLabs,项目名称:microservices,代码行数:18,代码来源:ChannelHistoryModuleImpl.java

示例4: getTradingCloseTime

import org.threeten.bp.ZoneId; //导入依赖的package包/类
/**
 * THIS IS NOT READY FOR PRIME TIME YET
 * @param exchangeSource a source of exchanges, we assume it provides ManageableExchanges
 * @param isoMic an external id with the ISO MIC code of the exchange
 * @param today the date today (to allow for changes in opening hours over time)
 * @param defaultTime a fallback time to use if a close time could not be established, if set to null, will return null in time field.
 * @return a pair of values, the end of trading period and the time zone or null if no exchange with that code was found.  Time can be null if defaultTime==null.
 */
public static Pair<LocalTime, ZoneId> getTradingCloseTime(ExchangeSource exchangeSource, ExternalId isoMic, LocalDate today, LocalTime defaultTime) {
  ManageableExchange exchange = (ManageableExchange) exchangeSource.getSingle(isoMic);
  if (exchange != null) {
    for (ManageableExchangeDetail detail : exchange.getDetail()) {
      if (detail.getPhaseName().equals("Trading") && 
          (detail.getCalendarStart() == null || detail.getCalendarStart().equals(today) || detail.getCalendarStart().isBefore(today)) &&
          (detail.getCalendarEnd() == null || detail.getCalendarEnd().equals(today) || detail.getCalendarEnd().isAfter(today))) {
        LocalTime endTime = detail.getPhaseEnd();
        if (endTime != null) {
          return Pairs.of(endTime, exchange.getTimeZone());
        }
      }
    }
    s_logger.warn("Couldn't find exchagne close time for {}, defaulting to supplied default", isoMic);
    return Pairs.of(defaultTime, exchange.getTimeZone());
  } else {
    return null;       
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:28,代码来源:ExchangeUtils.java

示例5: propertySet

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
  switch (propertyName.hashCode()) {
    case -294460212:  // uniqueId
      ((ManageableExchange) bean).setUniqueId((UniqueId) newValue);
      return;
    case -736922008:  // externalIdBundle
      ((ManageableExchange) bean).setExternalIdBundle((ExternalIdBundle) newValue);
      return;
    case 3373707:  // name
      ((ManageableExchange) bean).setName((String) newValue);
      return;
    case 979697809:  // regionIdBundle
      ((ManageableExchange) bean).setRegionIdBundle((ExternalIdBundle) newValue);
      return;
    case -2077180903:  // timeZone
      ((ManageableExchange) bean).setTimeZone((ZoneId) newValue);
      return;
    case -1335224239:  // detail
      ((ManageableExchange) bean).setDetail((List<ManageableExchangeDetail>) newValue);
      return;
  }
  super.propertySet(bean, propertyName, newValue, quiet);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:ManageableExchange.java

示例6: testUpdateUser

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@Test
public void testUpdateUser() {
  final ManageableUser input = new ManageableUser("bob");
  input.setAlternateIds(ExternalIdBundle.of("A", "B"));
  input.setEmailAddress("[email protected]");
  input.getProfile().setDisplayName("Test");
  input.getProfile().setZone(ZoneId.of("Europe/London"));
  input.setUniqueId(UID.withVersion("1"));
  final ManageableUser result = input.clone();
  result.getProfile().setDisplayName("Tester");
  result.setUniqueId(UID.withVersion("2"));
  
  when(_underlying.update(input)).thenReturn(UID.withVersion("2"));
  
  Response test = _resource.updateById(_uriInfo, OID.toString(), input);
  assertEquals(Status.OK.getStatusCode(), test.getStatus());
  assertEquals(UID.withVersion("2"), FudgeResponse.unwrap(test.getEntity()));
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:DataUserMasterResourceTest.java

示例7: createRootData

import org.threeten.bp.ZoneId; //导入依赖的package包/类
/**
 * Creates a new Freemarker root data.
 * <p>
 * This creates a new data object to be passed to Freemarker with some standard keys:
 * <ul>
 * <li>now - the current date-time using {@link OpenGammaClock}
 * <li>timeFormatter - a formatter that outputs the time as HH:mm:ss
 * <li>offsetFormatter - a formatter that outputs the time-zone offset
 * <li>homeUris - the home URIs
 * <li>baseUri - the base URI
 * <li>security - an instance of WebSecurity
 * </ul>
 * 
 * @param uriInfo  the URI information, not null
 * @return the root data, not null
 */
public static FlexiBean createRootData(UriInfo uriInfo) {
  FlexiBean out = FreemarkerOutputter.createRootData();
  out.put("homeUris", new WebHomeUris(uriInfo));
  out.put("baseUri", uriInfo.getBaseUri().toString());
  WebUser user = new WebUser(uriInfo);
  UserProfile profile = user.getProfile();
  if (profile != null) {
    Locale locale = profile.getLocale();
    ZoneId zone = profile.getZone();
    DateTimeFormatter dateFormatter = profile.getDateStyle().formatter(locale);
    DateTimeFormatter timeFormatter = profile.getTimeStyle().formatter(locale);
    ZonedDateTime now = ZonedDateTime.now(OpenGammaClock.getInstance().withZone(zone));
    out.put("now", now);
    out.put("locale", locale);
    out.put("timeZone", zone);
    out.put("dateFormatter", dateFormatter);
    out.put("timeFormatter", timeFormatter);
  }
  out.put("userSecurity", user);
  return out;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:38,代码来源:FreemarkerOutputter.java

示例8: toAndFromJson

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@Test
public void toAndFromJson() {
    Instant time = Instant.from(ZonedDateTime.of(2015, 8, 25, 11, 59, 30, 88 * 1000000, ZoneId.of("UTC")));
    Value value = new Value("no", "No", "no way!", time);

    JsonObject obj = (JsonObject) value.toJson();

    assertThat(obj, is(JsonUtils.object(
            "value", "no",
            "category", "No",
            "text", "no way!",
            "time", "2015-08-25T11:59:30.088Z"
    )));

    value = Value.fromJson(obj);

    assertThat(value.getValue(), is("no"));
    assertThat(value.getCategory(), is("No"));
    assertThat(value.getText(), is("no way!"));
    assertThat(value.getTime(), is(time));
}
 
开发者ID:rapidpro,项目名称:flows,代码行数:22,代码来源:ValueTest.java

示例9: buildDateContext

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@Test
public void buildDateContext() throws Exception {
    Instant now = ZonedDateTime.of(2015, 8, 24, 9, 44, 5, 0, ZoneId.of("Africa/Kigali")).toInstant();
    EvaluationContext container = new EvaluationContext(new HashMap<String, Object>(), ZoneId.of("Africa/Kigali"), DateStyle.DAY_FIRST, now);

    Map<String, String> context = RunState.buildDateContext(container);

    assertThat(context, hasEntry("*", "2015-08-24T09:44:05+02:00"));
    assertThat(context, hasEntry("now", "2015-08-24T09:44:05+02:00"));
    assertThat(context, hasEntry("today", "24-08-2015"));
    assertThat(context, hasEntry("tomorrow", "25-08-2015"));
    assertThat(context, hasEntry("yesterday", "23-08-2015"));

    container = new EvaluationContext(new HashMap<String, Object>(), ZoneId.of("Africa/Kigali"), DateStyle.MONTH_FIRST, now);

    context = RunState.buildDateContext(container);

    assertThat(context, hasEntry("*", "2015-08-24T09:44:05+02:00"));
    assertThat(context, hasEntry("now", "2015-08-24T09:44:05+02:00"));
    assertThat(context, hasEntry("today", "08-24-2015"));
    assertThat(context, hasEntry("tomorrow", "08-25-2015"));
    assertThat(context, hasEntry("yesterday", "08-23-2015"));
}
 
开发者ID:rapidpro,项目名称:flows,代码行数:24,代码来源:RunStateTest.java

示例10: dateTimeToExpiry

import org.threeten.bp.ZoneId; //导入依赖的package包/类
protected static Expiry dateTimeToExpiry(final FudgeDateTime datetime, final String timezone) {
  switch (datetime.getAccuracy()) {
    case NANOSECOND:
    case MILLISECOND:
    case MICROSECOND:
    case SECOND:
    case MINUTE:
      return new Expiry(ZonedDateTime.ofInstant(datetime.toInstant(), ZoneId.of(timezone)), ExpiryAccuracy.MIN_HOUR_DAY_MONTH_YEAR);
    case HOUR:
      return new Expiry(ZonedDateTime.ofInstant(datetime.toInstant(), ZoneId.of(timezone)), ExpiryAccuracy.HOUR_DAY_MONTH_YEAR);
    case DAY:
      return new Expiry(datetime.getDate().toLocalDate().atStartOfDay(ZoneId.of(timezone)), ExpiryAccuracy.DAY_MONTH_YEAR);
    case MONTH:
      return new Expiry(datetime.getDate().toLocalDate().atStartOfDay(ZoneId.of(timezone)), ExpiryAccuracy.MONTH_YEAR);
    case YEAR:
      return new Expiry(datetime.getDate().toLocalDate().atStartOfDay(ZoneId.of(timezone)), ExpiryAccuracy.YEAR);
    default:
      throw new IllegalArgumentException("Invalid accuracy value on " + datetime);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:ExpiryFudgeBuilder.java

示例11: testSerialisation

import org.threeten.bp.ZoneId; //导入依赖的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"));
}
 
开发者ID:gkopff,项目名称:gson-threeten-serialisers,代码行数:29,代码来源:ConvertersTest.java

示例12: expiryBeanToExpiry

import org.threeten.bp.ZoneId; //导入依赖的package包/类
public static Expiry expiryBeanToExpiry(final ExpiryBean bean) {
  if (bean == null) {
    return null;
  }
  final ZonedDateTimeBean zonedDateTimeBean = bean.getExpiry();

  final long epochSeconds = zonedDateTimeBean.getDate().getTime() / 1000;
  ZonedDateTime zdt = null;
  if (zonedDateTimeBean.getZone() == null) {
    zdt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSeconds), ZoneOffset.UTC);
  } else {
    zdt = ZonedDateTime.ofInstant(Instant.ofEpochSecond(epochSeconds), ZoneId.of(zonedDateTimeBean.getZone()));
  }

  return new Expiry(zdt, bean.getAccuracy());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:Converters.java

示例13: buildUser

import org.threeten.bp.ZoneId; //导入依赖的package包/类
private void buildUser(final ResultSet rs, final long docId) throws SQLException {
  int version = rs.getInt("VERSION");
  UniqueId uniqueId = UniqueId.of(getUniqueIdScheme(), Long.toString(docId), Integer.toString(version));
  ManageableUser user = new ManageableUser(rs.getString("USER_NAME"));
  user.setUniqueId(uniqueId);
  user.setPasswordHash(rs.getString("PASSWORD_HASH"));
  user.setStatus(extractEnum(rs.getString("STATUS"), UserAccountStatus.values()));
  user.setEmailAddress(rs.getString("EMAIL_ADDRESS"));
  user.getProfile().setDisplayName(rs.getString("DISPLAY_NAME"));
  user.getProfile().setLocale(Locale.forLanguageTag(rs.getString("LOCALE_TAG")));
  user.getProfile().setZone(ZoneId.of(rs.getString("TIME_ZONE")));
  user.getProfile().setDateStyle(DateStyle.valueOf(rs.getString("DATE_FMT_STYLE")));
  user.getProfile().setTimeStyle(TimeStyle.valueOf(rs.getString("TIME_FMT_STYLE")));
  _currUser = user;
  _users.add(user);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:DbUserMaster.java

示例14: toAndFromJson

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@Test
public void toAndFromJson() {
    JsonObject obj = (JsonObject) m_org.toJson();

    assertThat(obj, is(JsonUtils.object(
            "country", "RW",
            "primary_language", "eng",
            "timezone", "Africa/Kigali",
            "date_style", "day_first",
            "anon", false
    )));

    Org org = Org.fromJson(obj);

    assertThat(org.getCountry(), is("RW"));
    assertThat(org.getPrimaryLanguage(), is("eng"));
    assertThat(org.getTimezone(), is(ZoneId.of("Africa/Kigali")));
    assertThat(org.getDateStyle(), is(DateStyle.DAY_FIRST));
    assertThat(org.isAnon(), is(false));
}
 
开发者ID:rapidpro,项目名称:flows,代码行数:21,代码来源:OrgTest.java

示例15: plat4725

import org.threeten.bp.ZoneId; //导入依赖的package包/类
@Test(enabled = false)
/** 
 * Time between dates in different time zones, when one is near midnight.
 * Trouble arises because timeBetween(date1,date2) != -1 * timeBetween(date2,date1).
 * TimeCalculator computes time in ACTACT Daycount convention, hence fractions of a day are rounded to either 0 or 1 day's year fraction..
 */
public void plat4725() {
  ZoneId gmt = ZoneId.of("GMT");
  ZoneId london = ZoneId.of("+01:00");

  final ZonedDateTime date1 = ZonedDateTime.of(2013, 9, 24, 0, 0, 1, 0, london);
  final ZonedDateTime date2 = ZonedDateTime.of(2013, 9, 24, 9, 2, 45,936, gmt);
  final double time12 = TimeCalculator.getTimeBetween(date1, date2);
  final double time21 = TimeCalculator.getTimeBetween(date2, date1);
  assertEquals("TimeCalculator: across midnight", -1 * time12, time21, TOLERANCE);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:TimeCalculatorTest.java


注:本文中的org.threeten.bp.ZoneId类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。