List of usage examples for java.time.format DateTimeFormatter ofPattern
public static DateTimeFormatter ofPattern(String pattern)
From source file:com.github.drbookings.LocalDates.java
public static String getYearString(final LocalDate date) { return date.format(DateTimeFormatter.ofPattern("yyyy")); }
From source file:org.wallride.job.UpdatePostViewsItemReader.java
@Override protected void doReadPage() { if (results == null) { results = new CopyOnWriteArrayList<>(); } else {// w w w .ja v a 2 s.c o m results.clear(); } Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); GoogleAnalytics googleAnalytics = blog.getGoogleAnalytics(); if (googleAnalytics == null) { logger.warn("Configuration of Google Analytics can not be found"); return; } Analytics analytics = GoogleAnalyticsUtils.buildClient(googleAnalytics); try { LocalDate now = LocalDate.now(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); Analytics.Data.Ga.Get request = analytics.data().ga() .get(googleAnalytics.getProfileId(), now.minusYears(1).format(dateTimeFormatter), now.format(dateTimeFormatter), "ga:pageViews") // .setDimensions(String.format("ga:dimension%d", googleAnalytics.getCustomDimensionIndex())) // .setSort(String.format("-ga:dimension%d", googleAnalytics.getCustomDimensionIndex())) .setDimensions(String.format("ga:pagePath", googleAnalytics.getCustomDimensionIndex())) .setSort(String.format("-ga:pageViews", googleAnalytics.getCustomDimensionIndex())) .setStartIndex(getPage() * getPageSize() + 1).setMaxResults(getPageSize()); logger.info(request.toString()); final GaData gaData = request.execute(); if (CollectionUtils.isEmpty(gaData.getRows())) { return; } results.addAll(gaData.getRows()); } catch (IOException e) { logger.warn("Failed to synchronize with Google Analytics", e); throw new GoogleAnalyticsException(e); } // logger.info("Synchronization to google analytics is now COMPLETE. {} posts updated.", count); }
From source file:org.openlmis.fulfillment.web.util.StatusChangeDto.java
/** * Print createdDate for display purposes. * @return created date//from w w w.j a v a 2s .c o m */ @JsonIgnore public String printDate() { Locale locale = LocaleContextHolder.getLocale(); String datePattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.MEDIUM, FormatStyle.MEDIUM, Chronology.ofLocale(locale), locale); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(datePattern); return dateTimeFormatter.format(createdDate); }
From source file:com.pawandubey.griffin.model.Post.java
/** * Creates a Post with the given paramenter. * @param title the post title/* ww w . ja va2 s . c om*/ * @param auth the post author * @param dat the post date * @param loc the post's Path * @param cont the post's content * @param image * @param slu the post slug * @param lay the layout * @param tag the list of tags */ public Post(String title, String auth, LocalDate dat, Path loc, String cont, String image, String slu, String lay, List<String> tag) { this.title = title; author = auth; date = dat; prettyDate = date.format(DateTimeFormatter.ofPattern(config.getOutputDateFormat())); location = loc.toString(); setContent(cont); slug = slu; layout = lay; tags = tag; featuredImage = image; }
From source file:de.rkl.tools.tzconv.configuration.ConfiguredComponentsProvider.java
@Bean(name = BEAN_NAME_DATE_FORMATTER) public DateTimeFormatter configureDateFormatter() { return DateTimeFormatter.ofPattern("EEEE dd MMMM yyyy"); }
From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java
@Override public Collection<Collection<Object>> analyze(final Collection<String> parameter) { YearMonth requestedMonth = YearMonth.now(); if (parameter.size() > 0) { requestedMonth = YearMonth.parse(Iterables.get(parameter, 0)); }/*from w ww. j a v a 2 s.c om*/ Collection<Collection<Object>> result = Lists.newArrayList(); result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime", "Overtime", "Comment")); Duration overtime = Duration.ZERO; LocalDate currentday = requestedMonth.atDay(1); while (!currentday.isAfter(requestedMonth.atEndOfMonth())) { Collection<Booking> currentBookings = getBookingsForDay(currentday); if (hasCompleteBookings(currentBookings)) { String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE); LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime(); LocalTime endtime = Iterables.getLast(currentBookings).getEndtime(); Duration presence = calculatePresence(starttime, endtime); Duration worktime = calculateWorktime(currentBookings); Duration breaktime = calculateBreaktime(presence, worktime); Duration currentOvertime = calculateOvertime(worktime, currentday); overtime = overtime.plus(currentOvertime); result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")), endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence), formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime), validate(worktime, breaktime))); } currentday = currentday.plusDays(1); } return result; }
From source file:com.publictransitanalytics.scoregenerator.output.TimeQualifiedPointAccessibility.java
public TimeQualifiedPointAccessibility(final PathScoreCard scoreCard, final Grid grid, final Center center, final LocalDateTime time, final Duration tripDuration, final boolean backward, final Duration inServiceTime) throws InterruptedException { type = AccessibilityType.TIME_QUALIFIED_POINT_ACCESSIBILITY; direction = backward ? Direction.INBOUND : Direction.OUTBOUND; mapBounds = new Bounds(grid.getBounds()); this.center = new Point(center.getLogicalCenter().getPointRepresentation()); this.time = time.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss")); this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true); final ImmutableMap.Builder<Bounds, FullSectorReachInformation> builder = ImmutableMap.builder(); final TaskIdentifier task = new TaskIdentifier(time, center); final Set<Sector> sectors = grid.getAllSectors(); for (final Sector sector : sectors) { final MovementPath sectorPath = scoreCard.getBestPath(sector, task); if (sectorPath != null) { final Bounds sectorBounds = new Bounds(sector); builder.put(sectorBounds, new FullSectorReachInformation(sectorPath)); }//from w w w.j a v a 2s . co m } sectorPaths = builder.build(); totalSectors = grid.getReachableSectors().size(); inServiceSeconds = inServiceTime.getSeconds(); }
From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java
/** * @param includedTagsSet// ww w. ja v a 2 s. co m * @param date * @return */ private static Query queryBuilder(Set<String> includedTagsSet, LocalDateTime date) { List<String> includedTags = new ArrayList<>(); includedTags.addAll(includedTagsSet); String query = ""; if (includedTags.size() > 0) { query = replaceWhitespaces(includedTags.get(0)); for (int i = 1; i < includedTags.size(); i++) { query += " OR " + replaceWhitespaces(includedTags.get(i)); } } //System.out.println(date.toString()); //System.out.println(query); Query result = new Query(query); result.setResultType(Query.ResultType.popular); result.setSince(date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); return result; }
From source file:com.publictransitanalytics.scoregenerator.output.NetworkAccessibility.java
public NetworkAccessibility(final int taskCount, final ScoreCard scoreCard, final Grid grid, final Set<Sector> centerSectors, final LocalDateTime startTime, final LocalDateTime endTime, final Duration tripDuration, final Duration samplingInterval, final boolean backward, final Duration inServiceTime) throws InterruptedException { type = AccessibilityType.NETWORK_ACCESSIBILITY; direction = backward ? Direction.INBOUND : Direction.OUTBOUND; mapBounds = new Bounds(grid.getBounds()); boundsCenter = new Point(grid.getBounds().getCenter()); this.startTime = startTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss")); this.endTime = endTime.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss")); this.samplingInterval = DurationFormatUtils.formatDurationWords(samplingInterval.toMillis(), true, true); this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true); this.taskCount = taskCount; final Set<Sector> sectors = grid.getAllSectors(); totalSectors = grid.getReachableSectors().size(); final ImmutableMap.Builder<Bounds, Integer> countBuilder = ImmutableMap.builder(); for (final Sector sector : sectors) { if (scoreCard.hasPath(sector)) { final Bounds bounds = new Bounds(sector); countBuilder.put(bounds, scoreCard.getReachedCount(sector)); }//from w w w . j a v a 2 s .c o m } sectorCounts = countBuilder.build(); this.centerPoints = centerSectors.stream().map(sector -> new Point(sector.getBounds().getCenter())) .collect(Collectors.toSet()); sampleCount = centerPoints.size(); inServiceSeconds = inServiceTime.getSeconds(); }