List of usage examples for org.joda.time Duration Duration
public Duration(ReadableInstant start, ReadableInstant end)
From source file:kr.debop4j.timeperiod.tools.Durations.java
License:Apache License
/** * Create duration.//from w ww. ja v a 2 s . c om * * @param start the start * @param end the end * @return the duration */ public static Duration create(DateTime start, DateTime end) { return new Duration(start, end); }
From source file:kr.debop4j.timeperiod.tools.Durations.java
License:Apache License
/** * ?? @param year the year/*w w w . j a v a 2s. c o m*/ * * @return the duration */ public static Duration year(int year) { DateTime start = Times.startTimeOfYear(year); DateTime end = start.plusYears(1); return new Duration(start, end); }
From source file:kr.debop4j.timeperiod.tools.Durations.java
License:Apache License
/** * Halfyear duration./* w w w .j av a2s . co m*/ * * @param year the year * @param halfyear the halfyear * @return the duration */ public static Duration halfyear(int year, Halfyear halfyear) { DateTime start = startTimeOfHalfyear(year, halfyear); DateTime end = start.plusMonths(TimeSpec.MonthsPerHalfyear); return new Duration(start, end); }
From source file:kr.debop4j.timeperiod.tools.Durations.java
License:Apache License
/** * Quarter duration.// w w w . j ava 2 s. c o m * * @param year the year * @param quarter the quarter * @return the duration */ public static Duration quarter(int year, Quarter quarter) { DateTime start = startTimeOfQuarter(year, quarter); DateTime end = start.plusMonths(TimeSpec.MonthsPerQuarter); return new Duration(start, end); }
From source file:kr.debop4j.timeperiod.tools.Durations.java
License:Apache License
/** * Month duration./* w ww .ja va2s. c o m*/ * * @param year the year * @param monthOfYear the month of year * @return the duration */ public static Duration month(int year, int monthOfYear) { DateTime start = Times.startTimeOfMonth(year, monthOfYear); DateTime end = start.plusMonths(1); return new Duration(start, end); }
From source file:linkacademyswingproject.MainDisplay.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: if ((chosenTime != 0) || (chosenType != null)) { if (chosenColor != null) { if (chosenType.equals("Time")) { // int start = ((chosenTime)*60)*1000; int start = chosenTime; JPanel that = this; tmp = new Timer(start, new ActionListener() { @Override//ww w .ja va 2 s . c om public void actionPerformed(ActionEvent e) { JFrame wind = new JFrame("Alarm"); wind.setLayout(new FlowLayout()); Timer tmp = new Timer(jSlider1.getValue(), new ActionListener() { @Override public void actionPerformed(ActionEvent e) { wind.getContentPane().setBackground(chosenColor); disbleComponents(that, true); } }); tmp.start(); wind.setSize(new Dimension(300, 300)); wind.setVisible(true); } }); tmp.setRepeats(false); tmp.start(); disbleComponents(this, false); jButton2.setEnabled(true); } else { DateTime then = new DateTime(chosenDate.getTime()); DateTime now = new DateTime(); Duration diff = new Duration(now, then); Long lWait = diff.getMillis(); Integer wait = Integer.valueOf(lWait.intValue()); if (wait > 0) { JPanel that = this; tmp = new Timer(wait, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFrame wind = new JFrame("Alarm"); wind.setLayout(new FlowLayout()); Timer dur = new Timer(jSlider1.getValue(), new ActionListener() { @Override public void actionPerformed(ActionEvent e) { wind.getContentPane().setBackground(chosenColor); disbleComponents(that, true); } }); dur.start(); wind.setSize(new Dimension(300, 300)); wind.setVisible(true); } }); tmp.setRepeats(false); tmp.start(); disbleComponents(this, false); jButton2.setEnabled(true); } else { JOptionPane.showMessageDialog(null, "Date for alarm must be in the future"); } } } else { JOptionPane.showMessageDialog(null, "Must Select A color First"); } } else { JOptionPane.showMessageDialog(null, "Must Select Time First"); } }
From source file:manageBeans.AddAuctionMB.java
/** * Creates an auction with a product//from w w w.j av a 2 s . c o m * @param product * product to add to an auction * @return auction * the new created auction */ private Auction createAuction(Product product) { DateTime currentTime = new DateTime(); DateTime temp = new DateTime(endDate); DateTime end = new DateTime(temp.getYear(), temp.getMonthOfYear(), temp.getDayOfMonth(), endTime.getHours(), endTime.getMinutes()); // Calculate duration from start to end date Duration duration = new Duration(currentTime, end); long durationSeconds = duration.getStandardSeconds(); Auction auction = new Auction(); auction.setDuration(durationSeconds); auction.setInitPrice(price); // All auctions are published. TODO remove field from db auction.setPublished(true); Calendar calendar = Calendar.getInstance(); auction.setStartTime(calendar); auction.setProduct(product); auction.setUser(userFacade.getAuctionUser()); return auction; }
From source file:me.tongfei.progressbar.ProgressThread.java
License:Apache License
void refresh() { consoleStream.print('\r'); LocalDateTime currTime = LocalDateTime.now(); Duration elapsed = new Duration(progress.startTime.toDateTime(DateTimeZone.UTC), currTime.toDateTime(DateTimeZone.UTC)); String prefix = progress.task + " " + percentage() + " " + style.leftBracket; int maxSuffixLength = Math.max(0, consoleWidth - consoleRightMargin - prefix.length() - 10); String suffix = style.rightBracket + " " + ratio() + " (" + Util.formatDuration(elapsed) + " / " + eta(elapsed) + ") " + progress.extraMessage; if (suffix.length() > maxSuffixLength) suffix = suffix.substring(0, maxSuffixLength); length = consoleWidth - consoleRightMargin - prefix.length() - suffix.length(); StringBuilder sb = new StringBuilder(); sb.append(prefix);//w w w. ja va 2 s .c o m // case of indefinite progress bars if (progress.indefinite) { int pos = (int) (progress.current % length); sb.append(Util.repeat(style.space, pos)); sb.append(style.block); sb.append(Util.repeat(style.space, length - pos - 1)); } // case of definite progress bars else { sb.append(Util.repeat(style.block, progressIntegralPart())); if (progress.current < progress.max) { sb.append(style.fractionSymbols.charAt(progressFractionalPart())); sb.append(Util.repeat(style.space, length - progressIntegralPart() - 1)); } } sb.append(suffix); String line = sb.toString(); consoleStream.print(line); }
From source file:me.vertretungsplan.additionalinfo.BaseIcalParser.java
License:Mozilla Public License
@Override public AdditionalInfo getAdditionalInfo() throws IOException { AdditionalInfo info = new AdditionalInfo(); info.setTitle(getTitle());/* w w w .j ava2 s. com*/ String rawdata = httpGet(getIcalUrl(), "UTF-8"); if (shouldStripTimezoneInfo()) { Pattern pattern = Pattern.compile("BEGIN:VTIMEZONE.*END:VTIMEZONE", Pattern.DOTALL); rawdata = pattern.matcher(rawdata).replaceAll(""); } DateTime now = DateTime.now().withTimeAtStartOfDay(); List<ICalendar> icals = Biweekly.parse(rawdata).all(); List<Event> events = new ArrayList<>(); for (ICalendar ical : icals) { for (VEvent event : ical.getEvents()) { Event item = new Event(); TimeZone timezoneStart = getTimeZoneStart(ical, event); if (event.getDescription() != null) { item.description = event.getDescription().getValue(); } if (event.getSummary() != null) { item.summary = event.getSummary().getValue(); } if (event.getDateStart() != null) { item.startDate = new DateTime(event.getDateStart().getValue()); item.startHasTime = event.getDateStart().getValue().hasTime(); } else { continue; } if (event.getDateEnd() != null) { item.endDate = new DateTime(event.getDateEnd().getValue()); item.endHasTime = event.getDateEnd().getValue().hasTime(); } if (event.getLocation() != null) { item.location = event.getLocation().getValue(); } if (event.getUrl() != null) { item.url = event.getUrl().getValue(); } if (event.getRecurrenceRule() == null && item.endDate != null && (item.endDate.compareTo(now) < 0)) { continue; } else if (event.getRecurrenceRule() == null && (item.startDate.compareTo(now) < 0)) { continue; } if (event.getRecurrenceRule() != null && event.getRecurrenceRule().getValue().getUntil() != null && event.getRecurrenceRule().getValue().getUntil().compareTo(now.toDate()) < 0) { continue; } if (event.getRecurrenceRule() != null) { Duration duration = null; if (event.getDateEnd() != null) { duration = new Duration(new DateTime(event.getDateStart().getValue()), new DateTime(event.getDateEnd().getValue())); } DateIterator iterator = event.getDateIterator(timezoneStart); while (iterator.hasNext()) { Date date = iterator.next(); Event reccitem = item.clone(); reccitem.startDate = new DateTime(date); reccitem.endDate = reccitem.startDate.plus(duration); if (item.startDate.equals(reccitem.startDate)) continue; if (item.endDate != null && (item.endDate.compareTo(now) < 0)) { continue; } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) { continue; } events.add(reccitem); } } if (item.endDate != null && (item.endDate.compareTo(now) < 0)) { continue; } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) { continue; } events.add(item); } } Collections.sort(events, new Comparator<Event>() { @Override public int compare(Event o1, Event o2) { return o1.startDate.compareTo(o2.startDate); } }); StringBuilder content = new StringBuilder(); int count = 0; DateTimeFormatter fmtDt = DateTimeFormat.shortDateTime().withLocale(Locale.GERMANY); DateTimeFormatter fmtD = DateTimeFormat.shortDate().withLocale(Locale.GERMANY); DateTimeFormatter fmtT = DateTimeFormat.shortTime().withLocale(Locale.GERMANY); for (Event item : events) { if (count >= getMaxItemsCount()) { break; } else if (count != 0) { content.append("<br><br>\n\n"); } DateTime start = item.startDate; if (item.endDate != null) { DateTime end = item.endDate; if (!item.endHasTime) { end = end.minusDays(1); } content.append((item.startHasTime ? fmtDt : fmtD).print(start)); if (!end.equals(start)) { content.append(" - "); if (item.startHasTime && item.endHasTime && end.toLocalDate().equals(start.toLocalDate())) { content.append(fmtT.print(end)); } else { content.append((item.endHasTime ? fmtDt : fmtD).print(end)); } } } else { content.append(fmtDt.print(start)); } content.append("<br>\n"); content.append("<b>"); content.append(item.summary); content.append("</b>"); count++; } info.setText(content.toString()); return info; }
From source file:me.vertretungsplan.parser.ParserUtils.java
License:Mozilla Public License
static LocalDateTime parseDateTime(String string) { if (string == null) return null; reinitIfNeeded();/*from w w w .j a v a 2s . c om*/ string = string.replace("Stand:", "").replace("Import:", "").trim(); int i = 0; for (DateTimeFormatter f : dateTimeFormatters) { try { LocalDateTime dt = f.parseLocalDateTime(string); if (dateTimeFormats[i].contains("yyyy")) { return dt; } else { Duration currentYearDifference = abs(new Duration(DateTime.now(), dt.toDateTime())); Duration lastYearDifference = abs(new Duration(DateTime.now(), dt.minusYears(1).toDateTime())); Duration nextYearDifference = abs(new Duration(DateTime.now(), dt.plusYears(1).toDateTime())); if (lastYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() - 1).parseLocalDateTime(string); } else if (nextYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateTimeFormats[i]).withLocale(Locale.GERMAN) .withDefaultYear(f.getDefaultYear() + 1).parseLocalDateTime(string); } else { return dt; } } } catch (IllegalArgumentException e) { // Does not match this format, try the next one } i++; } // Does not match any known format :( return null; }