Java Code Examples for java.time.ZoneId#systemDefault()
The following examples show how to use
java.time.ZoneId#systemDefault() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlowLog.java From sofa-lookout with Apache License 2.0 | 6 votes |
@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(); }
Example 2
Source File: LicenseDeleteHook.java From bouncr with Eclipse Public License 1.0 | 5 votes |
@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())); }
Example 3
Source File: TestZoneId.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 4
Source File: JobStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * 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()); }
Example 5
Source File: TestZoneId.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 6
Source File: TestZoneId.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 7
Source File: MySqlConnection.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
/** * @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(); } }
Example 8
Source File: TestZoneId.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 9
Source File: TestZoneId.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 10
Source File: TestZoneId.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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); } }
Example 11
Source File: TestZoneId.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void test_systemDefault() { ZoneId test = ZoneId.systemDefault(); assertEquals(test.getId(), TimeZone.getDefault().getID()); }
Example 12
Source File: PrestoServiceImpl.java From yanagishima with Apache License 2.0 | 4 votes |
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)); }
Example 13
Source File: DateUtil.java From plumemo with Apache License 2.0 | 4 votes |
/** * 将long类型的timestamp转为LocalDateTime */ public static LocalDateTime getDateTimeOfTimestamp(long timestamp) { Instant instant = Instant.ofEpochMilli(timestamp); ZoneId zone = ZoneId.systemDefault(); return LocalDateTime.ofInstant(instant, zone); }
Example 14
Source File: ConnectionContextTest.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Test void shouldNotSetServerZoneId() { ConnectionContext context = new ConnectionContext(ZeroDateOption.USE_NULL, ZoneId.systemDefault()); assertThat(context.shouldSetServerZoneId()).isFalse(); }
Example 15
Source File: ConnectionContextTest.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Test void badSetServerZoneId() { ConnectionContext context = new ConnectionContext(ZeroDateOption.USE_NULL, ZoneId.systemDefault()); assertThatIllegalStateException().isThrownBy(() -> context.setServerZoneId(ZoneId.systemDefault())); }
Example 16
Source File: ZonedDateTimeAdapter.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
public static ZoneId getZoneId() { if (ZONE_ID == null) { ZONE_ID = ZoneId.systemDefault(); } return ZONE_ID; }
Example 17
Source File: ConnectionContextTest.java From r2dbc-mysql with Apache License 2.0 | 4 votes |
@Test void shouldNotSetServerZoneId() { ConnectionContext context = new ConnectionContext(ZeroDateOption.USE_NULL, ZoneId.systemDefault()); assertThat(context.shouldSetServerZoneId()).isFalse(); }
Example 18
Source File: ServletRequestMethodArgumentResolver.java From lams with GNU General Public License v2.0 | 4 votes |
public static Object resolveZoneId(HttpServletRequest request) { TimeZone timeZone = RequestContextUtils.getTimeZone(request); return (timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault()); }
Example 19
Source File: DateTimeBucketer.java From flink with Apache License 2.0 | 2 votes |
/** * 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()); }
Example 20
Source File: DateTimeBucketer.java From flink with Apache License 2.0 | 2 votes |
/** * 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()); }