/** Renders this TransferFile as wikitext for Commons. */ private String gen() { String t = sumSection + licSection; t = t.replaceAll("(?s)\\<!\\-\\-.*?\\-\\-\\>", ""); // strip comments t = t.replaceAll("(?i)\\n?\\[\\[(Category:).*?\\]\\]", ""); // categories don't transfer well. t = t.replaceAll("(?<=\\[\\[)(.+?\\]\\])", "w:$1"); // add enwp prefix to links t = t.replaceAll("(?i)\\[\\[(w::|w:w:)", "[[w:"); // Remove any double colons in interwiki links // Generate Upload Log Section t += "\n== {{Original upload log}} ==\n" + String.format( "{{Original description page|en.wikipedia|%s}}%n", FString.enc(enwp.nss(wpFN))) + "{| class=\"wikitable\"\n! {{int:filehist-datetime}} !! {{int:filehist-dimensions}} !! {{int:filehist-user}} " + "!! {{int:filehist-comment}}\n|-\n"; for (ImageInfo ii : imgInfoL) t += String.format( uLFmt, dtf.format(LocalDateTime.ofInstant(ii.timestamp, ZoneOffset.UTC)), ii.dimensions.x, ii.dimensions.y, ii.user, ii.user, ii.summary.replace("\n", " ")); t += "|}\n\n{{Subst:Unc}}"; if (mtc.useTrackingCat) t += "\n[[Category:Uploaded with MTC!]]"; return t; }
@Test public void testBuildBarData() { int requestId = 1; GregorianCalendar cal = new GregorianCalendar(); LocalDateTime date = LocalDateTime.ofInstant(cal.getTime().toInstant(), ZoneId.systemDefault()); double open = 1; double high = 2; double low = 0.5; double close = 1.5; int volume = 100; int count = 1; double wap = 1.0; boolean hasGaps = true; HistoricalData data = new HistoricalData(requestId, cal, open, high, low, close, volume, count, wap, hasGaps); BarData bar = HistoricalDataUtils.buildBarData(data); assertEquals(close, bar.getClose(), 0); assertEquals(open, bar.getOpen(), 0); assertEquals(high, bar.getHigh(), 0); assertEquals(low, bar.getLow(), 0); assertEquals(volume, bar.getVolume()); assertEquals(date, bar.getDateTime()); }
@Test public void testBasic() { System.out.println(Year.now()); System.out.println(Year.of(2015)); System.out.println(Year.isLeap(2016)); Locale locale = Locale.getDefault(); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.SHORT, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.NARROW, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL_STANDALONE, locale)); System.out.println(Month.of(8).ordinal()); System.out.println(Month.AUGUST.minus(2)); System.out.println(YearMonth.now()); System.out.println(MonthDay.now()); System.out.println(DayOfWeek.FRIDAY.plus(2)); System.out.println(DayOfWeek.of(1)); System.out.println( DayOfWeek.from(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()))); System.out.println(Period.between(Year.now().atDay(1), LocalDate.now())); System.out.println(ChronoUnit.DAYS.between(Year.now().atDay(1), LocalDate.now())); }
private static void conversionOldDateToNewDate() { System.out.println("Conversion old to new Date"); Date oldDate = new Date(); LocalDate newDate = LocalDateTime.ofInstant(oldDate.toInstant(), ZoneId.systemDefault()).toLocalDate(); System.out.println("Old Date: " + oldDate); System.out.println("New Date: " + newDate); }
@JsonIgnore public Optional<WorkLogEntry> getLastWorkLogEntryForToday() { return workLogEntries .stream() .filter( log -> LocalDateTime.ofInstant(log.getStartTime(), ZoneId.systemDefault()).getDayOfYear() == LocalDateTime.now().getDayOfYear()) .max(Comparator.comparing(log -> log.getStartTime())); }
@JsonIgnore public List<WorkLogEntry> getWorkLogEntriesForToday() { return workLogEntries .stream() .filter( log -> LocalDateTime.ofInstant(log.getStartTime(), ZoneId.systemDefault()).getDayOfYear() == LocalDateTime.now().getDayOfYear()) .collect(Collectors.toList()); }
@Override public Object nullSafeGet( ResultSet resultSet, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { Object timestamp = StandardBasicTypes.DATE.nullSafeGet(resultSet, names, session, owner); if (timestamp == null) { return null; } Date date = (Date) timestamp; Instant instant = Instant.ofEpochMilli(date.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); }
@Test public void testLocalDateTime() { System.out.println(LocalDateTime.now()); System.out.println(LocalDateTime.of(1994, Month.MAY, 15, 11, 30)); System.out.println(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault())); System.out.println(LocalDateTime.ofEpochSecond(1450749600, 0, ZoneOffset.ofHours(8))); System.out.printf("6 months from now: %s%n", LocalDateTime.now().plusMonths(6)); System.out.printf("6 days ago: %s%n", LocalDateTime.now().minusDays(6)); System.out.println(DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now())); System.out.println(DateTimeFormatter.ofPattern("MM-dd HH:mm").format(LocalDateTime.now())); }
public static void main(String[] args) throws IOException { Path dir = Paths.get(System.getProperty("user.home"), ".sandbox"); Files.createDirectories(dir); Path file = Paths.get(dir.toString(), "timestamp-test.txt"); List<String> lines = new ArrayList<>(); for (int i = 0; i < 10; i++) { lines.add(RandomStringUtils.randomAscii(20)); } Files.write(file, lines); FileTime fileTime = Files.getLastModifiedTime(file); System.out.println(fileTime); System.out.println(LocalDateTime.ofInstant(fileTime.toInstant(), ZoneId.systemDefault())); }
@JsonIgnore public List<WorkLogEntry> getWorkLogEntriesForWeek() { List<WorkLogEntry> list = workLogEntries .stream() .filter( log -> LocalDateTime.ofInstant(log.getStartTime(), ZoneId.systemDefault()) .get(WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear()) == LocalDateTime.now() .get(WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear())) .collect(Collectors.toList()); return list; }
/** * Check time zones on the IANA time and zone database * * @param args */ public static void main(String[] args) { ZoneId casaZone = ZoneId.of("Africa/Casablanca"); ZoneId defaultZone = TimeZone.getDefault().toZoneId(); LocalDate rightNow = LocalDate.now(); ZonedDateTime zoneDateTime = rightNow.atStartOfDay(casaZone); ZoneId parisZone = ZoneId.of("Europe/Paris"); LocalDateTime rightNowInTime = LocalDateTime.now(); ZonedDateTime rightNowInTimeInParis = rightNowInTime.atZone(parisZone); Instant thisMoment = Instant.now(); ZonedDateTime thisMomentInCasa = thisMoment.atZone(casaZone); ZoneId tokyoZone = ZoneId.of("Asia/Tokyo"); LocalDate thisInstantInTokyo = rightNowInTime.toLocalDate(); LocalDateTime timeFromThisMomentInTokyo = LocalDateTime.ofInstant(thisMoment, tokyoZone); System.out.println( String.format("In Tokyo right now is %s", timeFromThisMomentInTokyo.toString())); }
@Override public void logged(LogEntry entry) { try { // try to get a writer Writer writer = getWriter(); if (writer == null) { // silently fail, ELK service might just not be running return; } // prepare a exception string if the log contains an exception String exception = entry.getException() == null ? "" : " " + entry.getException().getMessage(); // format time of log Instant dateTimeInstant = new Date(entry.getTime()).toInstant(); LocalDateTime dateTime = LocalDateTime.ofInstant(dateTimeInstant, ZoneId.of("GMT")); // concatenate log string String log = m_formatter.format(dateTime) + " " + m_hostname + " " + m_frameworkUUID + " " + entry.getBundle().getSymbolicName() + " " + getLogLevel(entry.getLevel()) + " " + entry.getMessage() + exception; // write log string to logstash writer.write(log + "\n"); writer.flush(); } catch (Exception e) { // silently fail, ELK service might just not be running cleanup(); } }
// TODO: only for migration @Deprecated @RequestMapping(value = "/{storyId}", method = RequestMethod.PUT) public ResponseEntity newStoryWithFrames( @PathVariable String storyId, @RequestParam long creationDate, @RequestBody List<FrameRequest> framesRequests) { Story story = storiesRepository.save( new Story( storyId, LocalDateTime.ofInstant(Instant.ofEpochMilli(creationDate), ZoneOffset.UTC), new ArrayList<>())); Stream<Frame> frameStream = framesRequests.stream().map(FrameMapper::fromFrameRequest); frameStream.forEach( frame -> { framesRepository.save(frame); storiesRepository.save(story.addFrame(frame)); }); logger.info("new game with predefined frames started"); return ResponseEntity.created(URI.create("/stories/" + story.getId())).build(); }
public String getTimeText() { final Instant safe_time = time; if (safe_time == null) return ""; final LocalDateTime local = LocalDateTime.ofInstant(safe_time, ZoneId.systemDefault()); return local.format(formatter); }
/** * Generate the key representing the time period that the specified date time falls into * * @param aggregationPeriod the aggregation period for which the key will be generated * @param instant the date time * @return the time period key */ default String generateKey(AggregationPeriod aggregationPeriod, Instant instant) { return generateKey( aggregationPeriod.getCodeName(), LocalDateTime.ofInstant(instant, aggregationPeriod.getZone())); }
@Override public boolean includes(Date date) { Instant instant = Instant.ofEpochMilli(date.getTime()); LocalDate localDate = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); return localDate.getDayOfYear() == 1; }
private void setDateString(Date date) { Instant instant = Instant.ofEpochMilli(date.getTime()); LocalDate localDate = LocalDateTime.ofInstant(instant, ZoneId.of("GMT")).toLocalDate(); jDate.setDate(localDate); }
@Override public LocalDateTime convert(Date source) { return source == null ? null : LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault()); }
@Override public LocalDate convertToEntityAttribute(Date dbData) { Instant instant = Instant.ofEpochMilli(dbData.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); }
default LocalDateTime convertTimestampToLocalDateTime(Timestamp timestamp) { return LocalDateTime.ofInstant( Instant.ofEpochMilli(timestamp.getTime()), ZoneId.systemDefault()); }
private LocalDateTime getLocalDateFromUtc(String dateTime) { final DateTimeFormatter UTCTimeFormat = getUTCDateTimeFormat(); final ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTime, UTCTimeFormat); return LocalDateTime.ofInstant(zonedDateTime.toInstant(), ZoneId.of("Pacific/Auckland")); }