List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:DataRequestParser.java
public void inflateDataRequests(Set<DataRequest> dataRequestSet) { Iterator<DataRequest> iter = dataRequestSet.iterator(); // the goal here is to expand substitutions // so if start data and stop data are found // then each data request template needs to be expanded // to cover these dates String absoluteLocalPath;/*from ww w. j a v a 2 s. c om*/ DateTime startDate = this.getStartDate(); DateTime stopDate = this.getStopDate(); // the base case is that either start date or stop date is null // in this instance, inflated data set is equal to the original // dataRequest set if (startDate == null || stopDate == null) { // nothing to inflate while (iter.hasNext()) { this.routingServer.submitDataRequest(iter.next()); } return; } // calculate the number of days between start and stop date int numDays = Days.daysBetween(startDate, stopDate).getDays(); DataRequest tmpDataRequest; int i = 0; // loop while (iter.hasNext()) { tmpDataRequest = iter.next(); // loop between start and stop dates for (int j = 0; j <= numDays; j += 1) { // make new data request from template that has effective date set; DataRequest newDataRequest = tmpDataRequest.copy(); // set new date newDataRequest.setEffectiveDate(startDate.plusDays(j)); // update local path with date info //newDataRequest.applyDateToLocalPath(); absoluteLocalPath = this.dateKeyPathParser.replaceWithLiterals( newDataRequest.getLocalPathTemplate(), startDate.plusDays(j), newDataRequest.getKey()); newDataRequest.setLocalPathTemplate(absoluteLocalPath); //newDataRequest.print(); i += 1; // hand off to the routing server if (this.routingServer != null) { //newDataRequest.print(); this.routingServer.submitDataRequest(newDataRequest); } else { //System.out.println(i); } } } DateTimeFormatter fmt = DateTimeFormat.forPattern("y::D"); System.out.println("Start date: " + fmt.print(this.getStartDate()) + ", Stop date: " + fmt.print(this.getStopDate()) + ", Number of days: " + numDays); System.out.println("From templates " + dataRequestSet.size() + ", inflated " + i + " data requests ..."); }
From source file:DataConverter.java
public static Invoice[] readInvoice(Person[] persons, Customer[] customers, Product[] products) { try {//from w ww . j a va 2 s. c om Scanner s = new Scanner(new FileReader("data/Invoices.dat")); int count = s.nextInt(); //Number of entries. Invoice[] invoices = new Invoice[count]; //Array to hold invoices int iterator = 0; s.nextLine(); //Advance scanner to nextline while (s.hasNext()) { String inLine = s.nextLine(); //Make a string out of the next line String[] info; String[] invProducts; //Use this to handle product situation info = inLine.split(";"); //Create array of strings from each line, ; delimited //First, instantiate new invoice object invoices[iterator] = new Invoice(info[0]); for (Customer c : customers) { if (c.getCustomerCode().equalsIgnoreCase(info[1])) { invoices[iterator].setCustomer(c); } } //End customers for each for (Person p : persons) { if (p.getPersonCode().equals(info[2])) { invoices[iterator].setSalesPerson(p); } } // End persons for each //This is a String array of product information invProducts = info[3].split(","); for (String x : invProducts) { int index = x.indexOf(":"); //Get index of occurence of ":" String code = x.substring(0, index); //This is the product code for (Product p : products) { //Iterate over each product in product array if (p.getCode().equals(code)) { if (p.getClass().getSimpleName().equals("Equipment")) { invoices[iterator].addProduct(p, Integer.parseInt(x.substring(index + 1))); } else if (p.getClass().getSimpleName().equals("Consultation")) { invoices[iterator].addProduct(p, Integer.parseInt(x.substring(index + 1))); } else if (p.getClass().getSimpleName().equals("License")) { //First we need to get the number of days int index2; //PLacekeeper for substring formation DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); index2 = x.indexOf(":", index + 1); //Move index to next ":" String start = x.substring(index + 1, index2); String end = x.substring(index2 + 1); DateTime begin = new DateTime(DateTime.parse(start, fmt)); DateTime finish = new DateTime(DateTime.parse(end, fmt)); int period = Days.daysBetween(begin, finish).getDays(); invoices[iterator].addProduct(p, period); } } } //End for each product loop } //End for stringx:invProducts iterator++; } //End while s.close(); return invoices; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:JavaGlobal.java
License:Open Source License
private static void registerFormatters() { Formatters.register(DateTime.class, new Formatters.SimpleFormatter<DateTime>() { private final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); //ISO time without miliseconds @Override// w w w . j a v a2 s . c om public DateTime parse(String s, Locale locale) throws ParseException { return DATETIME_FORMATTER.parseDateTime(s); } @Override public String print(DateTime dateTime, Locale locale) { return dateTime.toString(DATETIME_FORMATTER); } }); Formatters.register(Instant.class, new Formatters.SimpleFormatter<Instant>() { @Override public Instant parse(String s, Locale locale) throws ParseException { return Utils.toInstant(s); } @Override public String print(Instant instant, Locale locale) { // ignores locale! return Utils.toString(instant); } }); Formatters.register(LocalDateTime.class, new Formatters.SimpleFormatter<LocalDateTime>() { @Override public LocalDateTime parse(String s, Locale locale) throws ParseException { return Utils.toLocalDateTime(s); } @Override public String print(LocalDateTime dateTime, Locale locale) { // ignores locale! return Utils.toString(dateTime); } }); Formatters.register(LocalDate.class, new Formatters.SimpleFormatter<LocalDate>() { @Override public LocalDate parse(String s, Locale locale) throws ParseException { return Utils.toLocalDate(s); } @Override public String print(LocalDate localDate, Locale locale) { // ignores locale! return Utils.toDateString(localDate); // happens to be the correct format } }); Formatters.register(EurocentAmount.class, new Formatters.SimpleFormatter<EurocentAmount>() { @Override public EurocentAmount parse(String s, Locale locale) throws ParseException { return EurocentAmount.parse(s); } @Override public String print(EurocentAmount eurocentAmount, Locale locale) { return eurocentAmount.toString(); } }); }
From source file:DataRequestStringParser.java
public String inflateDataRequests(Set<DataRequest> dataRequestSet) { Iterator<DataRequest> iter = dataRequestSet.iterator(); // the goal here is to expand substitutions // so if start data and stop data are found // then each data request template needs to be expanded // to cover these dates String absoluteLocalPath;/* ww w .java2s. co m*/ DateTime startDate = this.getStartDate(); DateTime stopDate = this.getStopDate(); try { this.xmlParser.reset(); } catch (IPWorksException e) { e.printStackTrace(); } // the base case is that either start date or stop date is null // in this instance, inflated data set is equal to the original // dataRequest set if (this.routingServer != null && (startDate == null || stopDate == null)) { // nothing to inflate while (iter.hasNext()) { this.routingServer.submitDataRequest(iter.next()); } return null; } // calculate the number of days between start and stop date int numDays = Days.daysBetween(startDate, stopDate).getDays(); DataRequest tmpDataRequest; int i = 0; // loop while (iter.hasNext()) { tmpDataRequest = iter.next(); // loop between start and stop dates for (int j = 0; j <= numDays; j += 1) { // make new data request from template that has effective date set; DataRequest newDataRequest = tmpDataRequest.copy(); // set new date newDataRequest.setEffectiveDate(startDate.plusDays(j)); // update local path with date info //newDataRequest.applyDateToLocalPath(); absoluteLocalPath = this.dateKeyPathParser.replaceWithLiterals( newDataRequest.getLocalPathTemplate(), startDate.plusDays(j), newDataRequest.getKey()); newDataRequest.setLocalPathTemplate(absoluteLocalPath); //newDataRequest.print(); i += 1; // hand off to the routing server if (this.routingServer != null) { //newDataRequest.print(); this.routingServer.submitDataRequest(newDataRequest); } else { //System.out.println(i); } } } DateTimeFormatter fmt = DateTimeFormat.forPattern("y::D"); return "Start date: " + fmt.print(startDate) + ", Stop date: " + fmt.print(stopDate) + ", Number of days: " + numDays + "\n" + "From templates " + dataRequestSet.size() + ", inflated " + i + " data requests ..."; }
From source file:act.data.DateTimeType.java
License:Apache License
protected DateTimeFormatter createDefaultJodaFormatter(AppConfig config) { String pattern = defaultPattern(config); return DateTimeFormat.forPattern(pattern).withLocale(config.locale()); }
From source file:act.data.JodaDateTimeCodecBase.java
License:Apache License
private DateTimeFormatter formatter(String pattern, Locale locale) { if (S.blank(pattern)) { return defaultFormatter(); }//ww w . j ava2 s .c o m return (isIsoStandard(pattern) ? isoFormatter() : DateTimeFormat.forPattern(pattern)).withLocale(locale); }
From source file:aDeleteME.DeleteME.java
public static void main(String[] args) { Random random = new Random(); DateTime startTime = new DateTime(random.nextLong()).withMillisOfSecond(0); Minutes minimumPeriod = Minutes.TWO; int minimumPeriodInSeconds = minimumPeriod.toStandardSeconds().getSeconds(); int maximumPeriodInSeconds = Hours.ONE.toStandardSeconds().getSeconds(); Seconds randomPeriod = Seconds.seconds(random.nextInt(maximumPeriodInSeconds - minimumPeriodInSeconds)); DateTime endTime = startTime.plus(minimumPeriod).plus(randomPeriod); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); System.out.println(dateTimeFormatter.print(startTime)); System.out.println(dateTimeFormatter.print(endTime)); }
From source file:android.com.wearface.Utils.java
License:Apache License
public static String getStringPatternFromDateTime(String pattern, DateTime date) { presenter = DateTimeFormat.forPattern(pattern); return presenter.print(date); }
From source file:AppPackage.timeDiff.java
public String timeDiff(String time1, String time2) { this.time1 = time1; this.time2 = time2; DateTimeFormatter format = DateTimeFormat.forPattern("HH:mm:ss"); DateTime dt1 = format.parseDateTime(time1); DateTime dt2 = format.parseDateTime(time2); long hours = Hours.hoursBetween(dt1, dt2).getHours() % 24; long minutes = Minutes.minutesBetween(dt1, dt2).getMinutes() % 60; // long seconds = Seconds.secondsBetween(dt1, dt2).getSeconds() % 60; String diffResult = String.format("%02d:%02d:00", hours, minutes); return diffResult; }
From source file:ar.com.wolox.wolmo.networking.retrofit.serializer.LocalDateSerializer.java
License:Open Source License
/** * Instance the formatter if it's null./* ww w.j av a 2 s . c om*/ */ private void initFormatter() { if (mDateTimeFormatter == null) { mDateTimeFormatter = DateTimeFormat.forPattern(getDateFormat()).withLocale(getLocale()); } }