Example usage for org.joda.time DateTime parse

List of usage examples for org.joda.time DateTime parse

Introduction

In this page you can find the example usage for org.joda.time DateTime parse.

Prototype

public static DateTime parse(String str, DateTimeFormatter formatter) 

Source Link

Document

Parses a DateTime from the specified string using a formatter.

Usage

From source file:com.yandex.money.api.model.showcase.components.uicontrols.Date.java

License:Open Source License

private static DateTime parse(String dateTime, DateTimeFormatter formatter) {
    return dateTime.equals("now") ? DateTime.parse(formatter.print(DateTime.now()), formatter)
            : DateTime.parse(dateTime, formatter);
}

From source file:com.yandex.money.api.typeadapters.JsonUtils.java

License:Open Source License

/**
 * Gets nullable DateTime from a JSON object using formatter.
 *
 * @param object     json object/*from   w  w  w. j a va 2  s . c  om*/
 * @param memberName member's name
 * @param formatter  {@link org.joda.time.DateTime}'s formatter.
 * @return {@link org.joda.time.DateTime} value
 */
public static DateTime getDateTime(JsonObject object, String memberName, DateTimeFormatter formatter) {
    String value = getString(object, memberName);
    return value == null ? null : DateTime.parse(value, checkNotNull(formatter, "formatter"));
}

From source file:com.zaradai.kunzite.trader.services.md.eod.csv.CsvEodReader.java

License:Apache License

private void readNext() throws Exception {
    String row = reader.readLine();
    String[] columns = row.split(",");
    // create new eod item
    last = new EodData();
    last.setSymbol(symbol);//from  www .  j  a  v a2s. c om
    last.setDate(DateTime.parse(columns[0], dateTimeFormatter));
    last.setOpen(Double.parseDouble(columns[1]));
    last.setHigh(Double.parseDouble(columns[2]));
    last.setLow(Double.parseDouble(columns[3]));
    last.setClose(Double.parseDouble(columns[4]));
    last.setClose(Long.parseLong(columns[5]));
}

From source file:connectivity.ClarolineService.java

/**
 * Gets the last updates./*from  w w  w  .  j a  va 2  s .c o  m*/
 * 
 * @param handler
 *            the handler to execute if the request is successful
 */
public void getUpdates(final AsyncHttpResponseHandler handler) {
    RequestParams p = ClarolineClient.getRequestParams(SupportedModules.USER, SupportedMethods.getUpdates);
    mClient.serviceQuery(p, new JsonHttpResponseHandler() {

        @Override
        public void onFailure(final Throwable e, final String array) {
            Log.e("ClarolineClient", "FAILURE ! :" + e.getLocalizedMessage());
        }

        @Override
        public void onFinish() {
            handler.onFinish();
        }

        @Override
        public void onSuccess(final JSONArray response) {
            handler.onSuccess(response.toString());
        }

        @SuppressWarnings("unchecked")
        @Override
        public void onSuccess(final JSONObject object) {

            Iterator<String> iterOnCours = object.keys();
            while (iterOnCours.hasNext()) {
                final String syscode = iterOnCours.next();
                final Cours upCours = new Select().from(Cours.class).where("Syscode = ?", syscode)
                        .executeSingle();

                if (upCours == null) {
                    getCourseList(new AsyncHttpResponseHandler() {
                        @Override
                        public void onSuccess(final String content) {
                            Cours cours = new Select().from(Cours.class).where("Syscode = ?", syscode)
                                    .executeSingle();

                            if (cours != null) {
                                updateCompleteCourse(cours, null, new AsyncHttpResponseHandler());
                            }
                        }
                    });
                    continue;
                } else {
                    try {
                        JSONObject jsonCours = object.getJSONObject(syscode);
                        Iterator<String> iterOnMod = jsonCours.keys();
                        while (iterOnMod.hasNext()) {
                            final String modKey = iterOnMod.next();
                            ResourceList upList = new Select().from(ResourceList.class)
                                    .where("Cours = ? AND label = ?", upCours, modKey).executeSingle();

                            if (upList == null) {
                                getToolListForCours(upCours, new AsyncHttpResponseHandler() {
                                    @Override
                                    public void onSuccess(final String content) {
                                        ResourceList list = new Select().from(ResourceList.class)
                                                .where("Cours = ? AND label = ?", upCours, modKey)
                                                .executeSingle();
                                        if (list != null) {
                                            getResourcesForList(list, new AsyncHttpResponseHandler());
                                        }
                                    }
                                });
                                continue;
                            } else {
                                try {
                                    JSONObject jsonRes = jsonCours.getJSONObject(modKey);
                                    Iterator<String> iterOnKeys = jsonRes.keys();
                                    while (iterOnKeys.hasNext()) {
                                        String resourceString = iterOnKeys.next();
                                        ModelBase upRes = new Select()
                                                .from(SupportedModules.getTypeForModule(modKey))
                                                .where("List = ?", upList).executeSingle();
                                        if (upRes == null) {
                                            getResourcesForList(upList, new AsyncHttpResponseHandler());
                                        } else {
                                            DateTime date = DateTime.parse(
                                                    jsonRes.optString(resourceString, ""),
                                                    DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
                                            upRes.setDate(date);
                                            upRes.setNotifiedDate(date);
                                        }
                                    }
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            handler.onSuccess(object.toString());
        }
    });
}

From source file:cz.muni.fi.mir.tools.Tools.java

License:Apache License

/**
 * Method converts input String with given pattern into DateTime.
 * @param input to be converted//from   w  w w . j a v a 2 s . c o  m
 * @param pattern input pattern
 * @return DateTime from given input
 */
public DateTime formatTime(String input, String pattern) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
    return DateTime.parse(input, dtf);
}

From source file:cz.muni.neural.network.util.OHLCReader.java

public static List<LabeledPoint> read(String file, int numberOfFeatures, int numberOfPoints,
        boolean skipWeekends, int period) throws IOException {

    BufferedReader br = null;/*from w  w  w  . j av  a2 s . c  o  m*/
    String line = "";
    List<Double> values = new ArrayList<Double>();
    List<Integer> weekendIndices = new ArrayList<Integer>();
    DateTime prevDate = null;
    DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy.MM.dd HH:mm");

    int lineCount = 0;

    try {
        br = new BufferedReader(new FileReader(file));
        while ((line = br.readLine()) != null) {

            String[] lineValues = line.split(",");
            int length = lineValues.length;

            if (length != 7) {
                throw new IOException("File has wrong format!");
            }

            //6th column is closing value
            values.add(Double.parseDouble(lineValues[5]));
            if (skipWeekends) {
                DateTime newDate = DateTime.parse(lineValues[0] + " " + lineValues[1], dtf);
                if (prevDate != null && Seconds.secondsBetween(prevDate, newDate).getSeconds() > period) {
                    weekendIndices.add(lineCount - 1);
                }
                prevDate = newDate;
            }
            lineCount++;
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    Object[] doubleVals = values.toArray();

    int finalLength = doubleVals.length - numberOfFeatures - 1;

    List<LabeledPoint> labeledPoints = new ArrayList<>();
    for (int i = 0; i < finalLength && labeledPoints.size() < numberOfPoints; i++) {
        //check if period contains weekend
        if (skipWeekends) {
            boolean skip = false;
            for (int j = i; j < i + numberOfFeatures - 1; j++) {
                if (weekendIndices.contains(j)) {
                    skip = true;
                    break;
                }
            }
            if (skip) {
                continue;
            }
        }

        double[] features = new double[numberOfFeatures];
        for (int j = 0; j < numberOfFeatures; j++) {
            features[j] = (double) doubleVals[i + j];
        }
        labeledPoints.add(new LabeledPoint((double) doubleVals[i + numberOfFeatures + 1], features));
    }

    System.out.println("Read " + labeledPoints.size() + " points.");

    return labeledPoints;
}

From source file:de.dbload.misc.DateTimeUtils.java

License:Apache License

/**
 * Creates a Joda DateTime object. The following date and time pattern will
 * be used://from  ww  w . j a v  a 2 s  . c o m
 * 
 * <pre>
 * yyyy-MM-dd HH24:MI:ss
 * </pre>
 *
 * @param dateAsString
 *            a String with pattern like 'yyyy-MM-dd HH24:MI:ss'
 * @return A Joda {@link DateTime}
 */
public static DateTime toJodaDateTime(String dateAsString) {
    DateTime dateTime = DateTime.parse(dateAsString, DEFAULT_FORMATTER_FOR_JODA_DATETIME);
    return dateTime;
}

From source file:de.fatalix.book.importer.BookExporterOld.java

private static void exportBatchWise(SolrServer server, File exportFolder, int batchSize, int offset, Gson gson)
        throws SolrServerException, IOException {

    QueryResponse response = SolrHandler.searchSolrIndex(server, "*:*", batchSize, offset);
    List<BookEntry> bookEntries = response.getBeans(BookEntry.class);
    System.out.println(//from   w w w  . ja  v a2 s  .  c  om
            "Retrieved " + (bookEntries.size() + offset) + " of " + response.getResults().getNumFound());
    for (BookEntry bookEntry : bookEntries) {
        String bookTitle = bookEntry.getTitle();
        bookTitle = bookTitle.replaceAll(":", " ");
        File bookFolder = new File(exportFolder, bookEntry.getAuthor() + "-" + bookTitle);
        bookFolder.mkdirs();
        if (bookEntry.getFile() != null && bookEntry.getCover() != null) {
            File bookData = new File(bookFolder, bookEntry.getAuthor() + "-" + bookTitle + ".mobi");
            Files.write(bookData.toPath(), bookEntry.getFile(), StandardOpenOption.CREATE_NEW);

            File coverData = new File(bookFolder, bookEntry.getAuthor() + "-" + bookTitle + ".jpg");
            Files.write(coverData.toPath(), bookEntry.getCover(), StandardOpenOption.CREATE_NEW);
            Date dreleaseDate = null;
            if (bookEntry.getReleaseDate() != null) {
                DateTime dtReleaseDate = DateTime.parse(bookEntry.getReleaseDate(),
                        DateTimeFormat.forPattern("YYYY-MM-dd"));
                dtReleaseDate = new DateTime(dtReleaseDate, DateTimeZone.UTC);
                dreleaseDate = dtReleaseDate.toDate();
            }
            DateTime dtUploadDate = new DateTime(DateTimeZone.UTC);

            File metaDataFile = new File(bookFolder, bookEntry.getAuthor() + "-" + bookTitle + ".json");
            String[] viewed = {};
            BookMetaData metaData = new BookMetaData(bookEntry.getAuthor(), bookEntry.getTitle(),
                    bookEntry.getIsbn(), bookEntry.getPublisher(), bookEntry.getDescription(),
                    bookEntry.getLanguage(), dreleaseDate, bookEntry.getMimeType(), dtUploadDate.toDate(),
                    viewed, bookEntry.getShared());
            gson.toJson(metaData);
            Files.write(metaDataFile.toPath(), gson.toJson(metaData).getBytes(), StandardOpenOption.CREATE_NEW);
        }

    }

    if (response.getResults().getNumFound() > offset) {
        exportBatchWise(server, exportFolder, batchSize, offset + batchSize, gson);
    }

}

From source file:de.fraunhofer.iosb.ilt.sta.model.ext.TimeInstant.java

License:Open Source License

public static TimeInstant parse(String value, DateTimeFormatter dtf) {
    return new TimeInstant(DateTime.parse(value, dtf));
}

From source file:eafit.cdei.asignacion.vo.Teacher.java

public void addCourseAvaliability(List<TimeDayLocation> pt) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("YY-MM-DDH:mm:ss");
    LocalDate mondayDate = LocalDate.parse("2014-10-20");

    meetTimeIntervals = new ArrayList<>();

    for (TimeDayLocation tdl : pt) {
        String key = tdl.getDow().dayOfWeek().getAsText() + tdl.getTimeStartString() + tdl.getTimeEndString();
        if (!mapCoursesAvaliability.containsKey(key)) {
            getMapCoursesAvaliability().put(key, tdl);
            getListAvaliability().add(tdl);

            for (int x = 0; x <= 6; x++) {
                LocalDate tmpStartDate = mondayDate.plusDays(x);
                String tmpDay = tmpStartDate.toString("EEEE");
                if (tmpStartDate.dayOfWeek().equals(tdl.getDow().dayOfWeek())) {
                    DateTime tmpStartDateTime = DateTime.parse(
                            tmpStartDate.toString("YY-MM-DD") + tdl.getTimeStart().toString("H:mm:ss"), fmt);
                    DateTime tmpStopDateTime = DateTime.parse(
                            tmpStartDate.toString("YY-MM-DD") + tdl.getTimeEnd().toString("H:mm:ss"), fmt);
                    meetTimeIntervals.add(new Interval(tmpStartDateTime, tmpStopDateTime));
                }/* w  w w.  ja v  a2s  .c  o m*/
            }
        }
    }
}