List of usage examples for org.joda.time DateTime parse
public static DateTime parse(String str, DateTimeFormatter formatter)
From source file:com.ro.ssc.app.client.controller.MainController.java
@Override public void initialize(URL location, ResourceBundle resources) { log.info("Initializing main controller"); File destDir = new File(MDB_PATH); if (!destDir.exists()) { destDir.mkdirs();/*from w w w .j a v a 2s .c o m*/ } else { File file = new File(MDB_PATH + "/status.txt"); try { if (!file.exists()) { file.createNewFile(); } String content = Files.toString(file, Charsets.UTF_8); try { if (DateTime.parse(content, dtf).isBeforeNow()) { return; } } catch (Exception e) { } log.debug("cont" + content + " file" + file); if (content.contains("111111111111111")) { Files.write(DateTime.now().toString(dtf), file, Charsets.UTF_8); Optional<String> result = UiCommonTools.getInstance().showExpDialogStatus("Licenta Expirata", "Va rugam contactati vanzatorul softului pentru codul de deblocare ", TrialKeyGenerator.generateKey(DateTime.now().toString(dtf))); if (result.isPresent()) { if (TrialKeyValidator.decodeKey(result.get()) .equals(Files.toString(file, Charsets.UTF_8).concat("0"))) { Files.write("NO_EXP", file, Charsets.UTF_8); } else { return; } } else { return; } } else if (!content.contains("NO_EXP")) { Files.append("1", file, Charsets.UTF_8); } } catch (FileNotFoundException ex) { log.error("Exception in finding file " + ex.getMessage()); } catch (IOException ex) { log.error("Exception in writing file " + ex.getMessage()); } } try { // load side menu final FXMLLoader sideMenuLoader = new FXMLLoader(); final AnchorPane sideMenu = sideMenuLoader.load(getClass().getResourceAsStream(SIDE_MENU_LAYOUT_FILE)); AnchorPane.setLeftAnchor(sideMenu, 0.0); AnchorPane.setTopAnchor(sideMenu, 0.0); AnchorPane.setRightAnchor(sideMenu, 0.0); AnchorPane.setBottomAnchor(sideMenu, 0.0); sideMenuContainer.getChildren().add(sideMenu); sideMenuContainer.getStylesheets().add(SIDE_MENU_CSS_FILE); ((SideMenuNoImagesController) sideMenuLoader.getController()).setMainController(this); // load status bar final FXMLLoader statusBarLoader = new FXMLLoader(); final AnchorPane statusBar = statusBarLoader .load(getClass().getResourceAsStream(STATUS_BAR_LAYOUT_FILE)); AnchorPane.setRightAnchor(statusBar, 10.0); statusBarContainer.getChildren().add(statusBar); statusBarContainer.getStylesheets().add(STATUS_BAR_CSS_FILE); handleSumaryViewLaunch(); } catch (Exception ex) { log.error("Failed to load components", ex); } }
From source file:com.ro.ssc.app.client.service.impl.DataProviderImplHelper.java
private static Set<String> getNeededPresence(Map<String, User> userData, Map<String, Map<String, ShiftData>> shiftData, String user, DateTime inidate, DateTime endate) { Set<String> result = new HashSet<>(); String userId = userData.get(user).getUserId().trim(); if (shiftData.containsKey(userId)) { for (String day : shiftData.get(userId).keySet()) { if (!shiftData.get(userId).get(day).getShiftId().equals("0") && DateTime.parse(day, dtf3).plusDays(1).isAfter(inidate) && DateTime.parse(day, dtf3).isBefore(endate.plusDays(1))) { result.add(day);//from www.j a va2s . c om } } } return result; }
From source file:com.ro.ssc.app.client.service.impl.DataProviderImplHelper.java
public static List<DailyData> getListPerDay(Map<String, User> userData, LocalTime time, Map<String, Map<String, ShiftData>> shiftData, Set<String> excludedGates, String userName, DateTime iniDate, DateTime endDate) { List<DailyData> result = new ArrayList(); Collections.sort(userData.get(userName).getEvents(), (c1, c2) -> c1.getEventDateTime().compareTo(c2.getEventDateTime())); Map<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> eventsPerDay; Map<DateTime, List<Event>> wrongPerDay; Set<String> usedDates = new HashSet<>(); String userId = userData.get(userName).getUserId().trim(); if (Configuration.IS_EXPIRED.getAsBoolean()) { eventsPerDay = splitPerDay(time, applyExcludeLogic(excludedGates, userData.get(userName).getEvents()).get(0), iniDate, endDate); wrongPerDay = splitPerDayWrong(time, applyExcludeLogic(excludedGates, userData.get(userName).getEvents()).get(1), iniDate, endDate); } else {//from w ww .j av a 2 s .c o m eventsPerDay = splitPerDay(time, applyExcludeLogic2(excludedGates, userData.get(userName).getEvents()).get(0), iniDate, endDate); wrongPerDay = splitPerDayWrong(time, applyExcludeLogic2(excludedGates, userData.get(userName).getEvents()).get(1), iniDate, endDate); } for (DateTime date = iniDate.withTimeAtStartOfDay(); date .isBefore(endDate.plusDays(1).withTimeAtStartOfDay()); date = date.plusDays(1)) { final DateTime currentDateAsDateTime = date; for (Map.Entry<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> entry : eventsPerDay.entrySet()) { if (entry.getKey().getKey().withTimeAtStartOfDay().isEqual(currentDateAsDateTime)) { Long duration = 0l; for (Pair<Event, Event> pair : entry.getValue()) { duration = duration + pair.getValue().getEventDateTime().getMillis() - pair.getKey().getEventDateTime().getMillis(); } Long pause = entry.getKey().getValue().getMillis() - entry.getKey().getKey().getMillis() - duration; Long overtime = 0l; Long latetime = 0l; Long earlytime = 0l; if (shiftData.containsKey(userId)) { final Map<String, ShiftData> shiftDataMapForUser = shiftData.get(userId); if (shiftDataMapForUser.containsKey(currentDateAsDateTime.toString(dtf3))) { ShiftData shiftDataInCurrentDate = shiftDataMapForUser .get(currentDateAsDateTime.toString(dtf3)); if (shiftDataInCurrentDate.getShiftId().equals("0")) { if (shiftDataInCurrentDate.isHasOvertime()) { overtime = duration; } } else { LocalTime officialStart = LocalTime .from(dtf4.parse(shiftDataInCurrentDate.getShiftStartHour())); LocalTime officialEnd = LocalTime .from(dtf4.parse(shiftDataInCurrentDate.getShiftEndHour())); long dailyPause = Long.valueOf(shiftDataInCurrentDate.getShiftBreakTime()) * 1000 * 60l; long dailyHours = officialEnd.isAfter(officialStart) ? 1000 * (officialEnd.toSecondOfDay() - officialStart.toSecondOfDay()) : 1000 * (officialEnd.toSecondOfDay() + (24 * 60 * 60 - officialStart.toSecondOfDay())); if (shiftDataInCurrentDate.isHasOvertime()) { if (pause > dailyPause) { overtime = duration - dailyHours + dailyPause; } else { overtime = duration + pause - dailyHours; duration = duration - (dailyPause - pause) > 0 ? duration - (dailyPause - pause) : 0; pause = dailyPause; } log.debug(userName + " data " + currentDateAsDateTime.toString(dtf3) + " overtime " + overtime); } else { if (duration < dailyHours - dailyPause) { overtime = duration - dailyHours + dailyPause; } } earlytime = entry.getKey().getValue().getSecondOfDay() < officialEnd.toSecondOfDay() ? 1000 * (officialEnd.toSecondOfDay() - entry.getKey().getValue().getSecondOfDay()) : 0l; latetime = entry.getKey().getKey().getSecondOfDay() > officialStart.toSecondOfDay() ? 1000 * (entry.getKey().getKey().getSecondOfDay() - officialStart.toSecondOfDay()) : 0l; } } } result.add(new DailyData(userId, date, entry.getKey().getKey().toString(dtf), entry.getKey().getValue().toString(dtf), earlytime, duration, duration, pause, overtime, latetime, wrongPerDay.get(currentDateAsDateTime))); usedDates.add(currentDateAsDateTime.toString(dtf3)); } } } for (String day : getNeededPresence(userData, shiftData, userName, iniDate, endDate)) { if (!usedDates.contains(day)) { ShiftData shiftDataInCurrentDate = shiftData.get(userId).get(day); LocalTime officialStart = LocalTime.from(dtf4.parse(shiftDataInCurrentDate.getShiftStartHour())); LocalTime officialEnd = LocalTime.from(dtf4.parse(shiftDataInCurrentDate.getShiftEndHour())); long dailyPause = Long.valueOf(shiftDataInCurrentDate.getShiftBreakTime()) * 1000 * 60l; long dailyHours = officialEnd.isAfter(officialStart) ? 1000 * (officialEnd.toSecondOfDay() - officialStart.toSecondOfDay()) : 1000 * (officialEnd.toSecondOfDay() + (24 * 60 * 60 - officialStart.toSecondOfDay())); if (wrongPerDay.containsKey(DateTime.parse(day, dtf3))) { if (wrongPerDay.get(DateTime.parse(day, dtf3)).size() > 0) { String ev = wrongPerDay.get(DateTime.parse(day, dtf3)).get(0).getEventDateTime() .toString(dtf); Boolean isIn = wrongPerDay.get(DateTime.parse(day, dtf3)).get(0).getAddr().contains("In"); result.add(new DailyData(userId, DateTime.parse(day, dtf3), isIn == true ? ev : "", isIn == false ? ev : "", 0, 0, 0, 0, dailyPause - dailyHours, 0, wrongPerDay.get(DateTime.parse(day, dtf3)))); } else { result.add(new DailyData(userId, DateTime.parse(day, dtf3), "", "", 0, 0, 0, 0, dailyPause - dailyHours, 0, new ArrayList<>())); } } else { result.add(new DailyData(userId, DateTime.parse(day, dtf3), "", "", 0, 0, 0, 0, dailyPause - dailyHours, 0, new ArrayList<>())); } } } return result; }
From source file:com.ro.ssc.app.client.utils.ExcelReader.java
/** * * @param file/*from ww w . j a v a 2s . co m*/ * @return */ public static Map<String, User> readExcel(File file) { Map<String, User> result = new HashMap<>(); List<Event> events; try { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file)); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row; HSSFCell cell; int rows; // No of rows rows = sheet.getPhysicalNumberOfRows(); int cols = 0; // No of columns int tmp; // This trick ensures that we get the data properly even if it doesn't start from first few rows for (int i = 0; i < 10 || i < rows; i++) { row = sheet.getRow(i); if (row != null) { tmp = sheet.getRow(i).getPhysicalNumberOfCells(); if (tmp > cols) { cols = tmp; } } } DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss EEEE"); for (int r = 1; r < rows; r++) { row = sheet.getRow(r); if (row != null) { try { String user = WordUtils .capitalizeFully(row.getCell(ExcelEnum.USER_NAME.getAsInteger()).toString().trim()); if (row.getCell(ExcelEnum.PASSED.getAsInteger()).toString().trim().equals("1.0")) { if (result.containsKey(user)) { events = result.get(user).getEvents(); events.add(new Event( DateTime.parse(row.getCell(ExcelEnum.TIMESTAMP.getAsInteger()).toString(), dtf), row.getCell(ExcelEnum.DESCRIPTION.getAsInteger()).toString(), row.getCell(ExcelEnum.ADDRESS.getAsInteger()).toString().trim(), row.getCell(ExcelEnum.PASSED.getAsInteger()).toString().trim() .equals("1.0"))); result.get(user).setEvents(events); } else { events = new ArrayList(); events.add(new Event( DateTime.parse(row.getCell(ExcelEnum.TIMESTAMP.getAsInteger()).toString(), dtf), row.getCell(ExcelEnum.DESCRIPTION.getAsInteger()).toString().trim(), row.getCell(ExcelEnum.ADDRESS.getAsInteger()).toString().trim(), row.getCell(ExcelEnum.PASSED.getAsInteger()).toString().trim() .equals("1.0"))); String id = row.getCell(ExcelEnum.USER_ID.getAsInteger()).toString().trim(); result.put(user, new User(user, id.contains(".") ? id.split("\\.")[0] : id, row.getCell(ExcelEnum.CARD_NO.getAsInteger()).toString().trim(), WordUtils.capitalizeFully( row.getCell(ExcelEnum.DEPARTMENT.getAsInteger()).toString().trim()), events)); } } } catch (Exception e) { log.error("Exception" + e.getMessage()); } } } } catch (Exception ioe) { log.error("Exception" + ioe.getMessage()); } return result; }
From source file:com.rusticisoftware.tincan.http.HTTPResponse.java
License:Apache License
public DateTime getLastModified() { DateTimeFormatter RFC1123_DATE_TIME_FORMATTER = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'") .withZoneUTC();/* w ww. j a va 2s . c om*/ try { return DateTime.parse(this.getHeader("Last-Modified"), RFC1123_DATE_TIME_FORMATTER); } catch (Exception parseException) { return null; } }
From source file:com.snake.salarycounter.activities.MainActivity.java
@OnClick(R.id.button) void onButtonClicked() { MyLogic lgc = new MyLogic(DateTime.now(), DateTime.now()); lgc.RecalcDay(DateTime.parse("16.05.2016", DateTimeFormat.forPattern("dd.mm.yyyy"))); }
From source file:com.sonicle.webtop.core.sdk.BaseSettings.java
License:Open Source License
public DateTime getDateTime(String key, DateTime defaultValue, DateTimeZone dtz) { DateTimeFormatter dtf = DateTimeUtils.createYmdHmsFormatter(dtz); String value = getString(key, null); return (value == null) ? defaultValue : DateTime.parse(value, dtf); }
From source file:com.threewks.thundr.google.analytics.admin.AnalyticsController.java
License:Apache License
private DateTime parseDate(String date, DateTime defaultDate) { try {/*from w w w .jav a2 s. c o m*/ return DateTime.parse(date, formatter); } catch (Exception e) { return defaultDate; } }
From source file:com.yahoo.bard.webservice.web.apirequest.ApiRequestImpl.java
License:Apache License
/** * Get datetime from the given input text based on granularity. * * @param now current datetime to compute the floored date based on granularity * @param granularity granularity to truncate the given date to. * @param dateText start/end date text which could be actual date or macros * @param timeFormatter a time zone adjusted date time formatter * * @return joda datetime of the given start/end date text or macros * * @throws BadApiRequestException if the granularity is "all" and a macro is used *///from w w w . ja v a2 s . c o m public static DateTime getAsDateTime(DateTime now, Granularity granularity, String dateText, DateTimeFormatter timeFormatter) throws BadApiRequestException { //If granularity is all and dateText is macro, then throw an exception TimeMacro macro = TimeMacro.forName(dateText); if (macro != null) { if (granularity instanceof AllGranularity) { LOG.debug(INVALID_INTERVAL_GRANULARITY.logFormat(macro, dateText)); throw new BadApiRequestException(INVALID_INTERVAL_GRANULARITY.format(macro, dateText)); } return macro.getDateTime(now, (TimeGrain) granularity); } return DateTime.parse(dateText, timeFormatter); }
From source file:com.yahoo.bard.webservice.web.DataApiRequest.java
License:Apache License
/** * Get datetime from the given input text based on granularity. * * @param now current datetime to compute the floored date based on granularity * @param granularity granularity to truncate the given date to. * @param dateText start/end date text which could be actual date or macros * @param timeFormatter a time zone adjusted date time formatter * * @return joda datetime of the given start/end date text or macros * * @throws BadApiRequestException if the granularity is "all" and a macro is used */// w ww . j a v a 2 s. co m public static DateTime getAsDateTime(DateTime now, Granularity granularity, String dateText, DateTimeFormatter timeFormatter) throws BadApiRequestException { //If granularity is all and dateText is macro, then throw an exception TimeMacros macro = TimeMacros.forName(dateText); if (macro != null) { if (granularity instanceof AllGranularity) { LOG.debug(INVALID_INTERVAL_GRANULARITY.logFormat(macro, dateText)); throw new BadApiRequestException(INVALID_INTERVAL_GRANULARITY.format(macro, dateText)); } return macro.getDateTime(now, (TimeGrain) granularity); } return DateTime.parse(dateText, timeFormatter); }