java.time.ZoneId#systemDefault ( )源码实例Demo

下面列出了java.time.ZoneId#systemDefault ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sofa-lookout   文件: SlowLog.java
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    ZoneId zoneId = ZoneId.systemDefault();
    LocalDateTime start = LocalDateTime.ofInstant(
        Instant.ofEpochMilli(Long.parseLong(this.start)), zoneId);
    LocalDateTime end = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(this.end)),
        zoneId);
    sb.append(duration).append("ms|");
    sb.append(query).append('|');
    sb.append(start).append('|');
    sb.append(end).append('|');
    sb.append(step).append("s|");
    sb.append(exclusions != null ? exclusions.toString() : "");
    return sb.toString();
}
 
源代码2 项目: bouncr   文件: LicenseDeleteHook.java
@Override
public void run(RestContext context) {
    final EntityManager em = ((EntityManageable) context.getRequest()).getEntityManager();
    LicenseKey licenseKey = some(context.getRequest().getCookies(),
            c->c.get(config.getCookieName()),
            Cookie::getValue,
            LicenseKey::new).orElse(null);

    if (licenseKey == null) return;

    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<UserLicense> query = cb.createQuery(UserLicense.class);
    final Root<UserLicense> root = query.from(UserLicense.class);
    query.where(cb.equal(root.get("licenseKey"), licenseKey.asBytes()));
    em.createQuery(query).getResultStream()
            .forEach(em::remove);

    Cookie cookie = Cookie.create(config.getCookieName(), licenseKey.asString());
    ZoneId zone = ZoneId.systemDefault();
    Date expires = Date.from(
            ZonedDateTime.of(LocalDate.now()
                    .minusYears(10)
                    .atTime(0, 0), zone)
                    .toInstant());
    cookie.setExpires(expires);
    cookie.setPath("/");
    context.setHeaders(Headers.of("Set-Cookie", cookie.toHttpString()));

}
 
源代码3 项目: openjdk-jdk8u-backup   文件: TestZoneId.java
@Test(expectedExceptions = ZoneRulesException.class)
public void test_systemDefault_unableToConvert_unknownId() {
    TimeZone current = TimeZone.getDefault();
    try {
        TimeZone.setDefault(new SimpleTimeZone(127, "SomethingWeird"));
        ZoneId.systemDefault();
    } finally {
        TimeZone.setDefault(current);
    }
}
 
源代码4 项目: openjdk-8-source   文件: TestZoneId.java
@Test(expectedExceptions = ZoneRulesException.class)
public void test_systemDefault_unableToConvert_unknownId() {
    TimeZone current = TimeZone.getDefault();
    try {
        TimeZone.setDefault(new SimpleTimeZone(127, "SomethingWeird"));
        ZoneId.systemDefault();
    } finally {
        TimeZone.setDefault(current);
    }
}
 
源代码5 项目: jdk8u-jdk   文件: TestZoneId.java
@Test(expectedExceptions = ZoneRulesException.class)
public void test_systemDefault_unableToConvert_unknownId() {
    TimeZone current = TimeZone.getDefault();
    try {
        TimeZone.setDefault(new SimpleTimeZone(127, "SomethingWeird"));
        ZoneId.systemDefault();
    } finally {
        TimeZone.setDefault(current);
    }
}
 
源代码6 项目: r2dbc-mysql   文件: MySqlConnection.java
/**
 * @param id the ID/name of MySQL time zone
 * @return the {@link ZoneId} from {@code id}, or system default timezone if not found.
 */
private static ZoneId convertZoneId(String id) {
    String realId;

    if (id.startsWith(ZONE_PREFIX_POSIX) || id.startsWith(ZONE_PREFIX_RIGHT)) {
        realId = id.substring(PREFIX_LENGTH);
    } else {
        realId = id;
    }

    try {
        switch (realId) {
            case "Factory":
                // Looks like the "Factory" time zone is UTC.
                return ZoneOffset.UTC;
            case "America/Nuuk":
                // They are same timezone including DST.
                return ZoneId.of("America/Godthab");
            case "ROC":
                // Republic of China, 1912-1949, very very old time zone.
                // Even the ZoneId.SHORT_IDS does not support it.
                // Is there anyone using this time zone, really?
                // Don't think so, but should support it for compatible.
                // Just use GMT+8, id is equal to +08:00.
                return ZoneId.of("+8");
            default:
                return ZoneId.of(realId, ZoneId.SHORT_IDS);
        }
    } catch (DateTimeException e) {
        logger.warn("The server timezone is <{}> that's unknown, trying to use system default timezone", id);
        return ZoneId.systemDefault();
    }
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: TestZoneId.java
@Test(expectedExceptions = DateTimeException.class)
public void test_systemDefault_unableToConvert_badFormat() {
    TimeZone current = TimeZone.getDefault();
    try {
        TimeZone.setDefault(new SimpleTimeZone(127, "Something Weird"));
        ZoneId.systemDefault();
    } finally {
        TimeZone.setDefault(current);
    }
}
 
源代码8 项目: openjdk-jdk9   文件: TestZoneId.java
@Test(expectedExceptions = ZoneRulesException.class)
public void test_systemDefault_unableToConvert_unknownId() {
    TimeZone current = TimeZone.getDefault();
    try {
        TimeZone.setDefault(new SimpleTimeZone(127, "SomethingWeird"));
        ZoneId.systemDefault();
    } finally {
        TimeZone.setDefault(current);
    }
}
 
源代码9 项目: nexus-public   文件: JobStoreImplTest.java
/**
 * Simulate a job that has run longer than the next fire time such that it misfires, but will not fire again because
 * the end of the trigger window has passed.
 */
@Test
public void testTriggerPastDueMisfireButWillNotFire() throws Exception {
  JobDetail jobDetail = JobBuilder.newJob(MyNonConcurrentJob.class).storeDurably(true).build();
  jobStore.storeJob(jobDetail, false);

  ZoneId zone = ZoneId.systemDefault();

  Date baseFireTimeDate = DateBuilder.evenMinuteDateAfterNow();
  LocalDateTime baseDateTime = LocalDateTime.ofInstant(baseFireTimeDate.toInstant(), zone);
  LocalDateTime startAt = baseDateTime.minusMinutes(5);
  LocalDateTime endAt = baseDateTime.minusMinutes(1);
  LocalDateTime nextFireTime = startAt.plusMinutes(1);

  SimpleScheduleBuilder simple = SimpleScheduleBuilder.simpleSchedule()
      .withIntervalInMinutes(1);
  OperableTrigger trigger = (OperableTrigger) TriggerBuilder.newTrigger()
      .forJob(jobDetail)
      .withSchedule(simple)
      .startAt(Date.from(startAt.atZone(zone).toInstant()))
      .endAt(Date.from(endAt.atZone(zone).toInstant()))
      .build();

  // misfire the trigger and set the next fire time in the past
  trigger.updateAfterMisfire(null);
  trigger.setNextFireTime(Date.from(nextFireTime.atZone(zone).toInstant()));
  trigger.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT);
  jobStore.storeTrigger(trigger, false);

  List<OperableTrigger> acquiredTriggers =
      jobStore.acquireNextTriggers(baseFireTimeDate.getTime(), 4, 1000L);
  assertEquals(0, acquiredTriggers.size());
}
 
源代码10 项目: openjdk-8   文件: TestZoneId.java
@Test(expectedExceptions = ZoneRulesException.class)
public void test_systemDefault_unableToConvert_unknownId() {
    TimeZone current = TimeZone.getDefault();
    try {
        TimeZone.setDefault(new SimpleTimeZone(127, "SomethingWeird"));
        ZoneId.systemDefault();
    } finally {
        TimeZone.setDefault(current);
    }
}
 
源代码11 项目: timbuctoo   文件: ZonedDateTimeAdapter.java
public static ZoneId getZoneId() {
  if (ZONE_ID == null) {
    ZONE_ID = ZoneId.systemDefault();
  }
  return ZONE_ID;
}
 
源代码12 项目: plumemo   文件: DateUtil.java
/**
 * 将long类型的timestamp转为LocalDateTime
 */
public static LocalDateTime getDateTimeOfTimestamp(long timestamp) {
    Instant instant = Instant.ofEpochMilli(timestamp);
    ZoneId zone = ZoneId.systemDefault();
    return LocalDateTime.ofInstant(instant, zone);
}
 
源代码13 项目: openjdk-8   文件: TestZoneId.java
public void test_systemDefault() {
    ZoneId test = ZoneId.systemDefault();
    assertEquals(test.getId(), TimeZone.getDefault().getID());
}
 
源代码14 项目: yanagishima   文件: PrestoServiceImpl.java
private static ClientSession buildClientSession(String server, String user, String source, String catalog, String schema, Map<String, String> properties) {
    return new ClientSession(URI.create(server), user, source, Optional.empty(), ImmutableSet.of(), null, catalog,
                             schema, null, ZoneId.systemDefault(), Locale.getDefault(),
                             ImmutableMap.of(), properties, emptyMap(), emptyMap(), ImmutableMap.of(), null, new Duration(2, MINUTES));
}
 
源代码15 项目: r2dbc-mysql   文件: ConnectionContextTest.java
@Test
void shouldNotSetServerZoneId() {
    ConnectionContext context = new ConnectionContext(ZeroDateOption.USE_NULL, ZoneId.systemDefault());
    assertThat(context.shouldSetServerZoneId()).isFalse();
}
 
源代码16 项目: r2dbc-mysql   文件: ConnectionContextTest.java
@Test
void badSetServerZoneId() {
    ConnectionContext context = new ConnectionContext(ZeroDateOption.USE_NULL, ZoneId.systemDefault());
    assertThatIllegalStateException().isThrownBy(() -> context.setServerZoneId(ZoneId.systemDefault()));
}
 
源代码17 项目: r2dbc-mysql   文件: ConnectionContextTest.java
@Test
void shouldNotSetServerZoneId() {
    ConnectionContext context = new ConnectionContext(ZeroDateOption.USE_NULL, ZoneId.systemDefault());
    assertThat(context.shouldSetServerZoneId()).isFalse();
}
 
public static Object resolveZoneId(HttpServletRequest request) {
	TimeZone timeZone = RequestContextUtils.getTimeZone(request);
	return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault());
}
 
源代码19 项目: flink   文件: DateTimeBucketer.java
/**
 * Creates a new {@code DateTimeBucketer} with the given date/time format string using JVM's default timezone.
 *
 * @param formatString The format string that will be given to {@code DateTimeFormatter} to determine
 *                     the bucket path.
 */
public DateTimeBucketer(String formatString) {
	this(formatString, ZoneId.systemDefault());
}
 
源代码20 项目: flink   文件: DateTimeBucketer.java
/**
 * Creates a new {@code DateTimeBucketer} with the given date/time format string using JVM's default timezone.
 *
 * @param formatString The format string that will be given to {@code DateTimeFormatter} to determine
 *                     the bucket path.
 */
public DateTimeBucketer(String formatString) {
	this(formatString, ZoneId.systemDefault());
}