List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate(Object instant)
From source file:com.nitdlibrary.EditViewStudent.java
/** * THIS FUNCTION CALCULATES DATA FOR FILTERED RESULTSET AND UPDATES THE LABELS * @param from//from www . j a v a2s. c o m * @param to */ private void calculateFilteredPerformance(LocalDate from, LocalDate to) throws SQLException { issueFilteredResultSet.beforeFirst(); Date returnDate = null, dueDate = null; LocalDate returnDateJoda = null, dueDateJoda = null; int totalIssued = 0, returned = 0, fine = 0, currentIssue = 0; int flag = 0; //incremented when today is > due date and return_date is null. it means that some books are not returned and fine calc is shown wrt today while (issueFilteredResultSet.next()) { totalIssued++; if (issueFilteredResultSet.getString("return_date") != null) returned++; DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { dueDate = format.parse(issueFilteredResultSet.getString("due_date")); /** * IF BOOK HAS NOT BEEN RETURNED AND TODAY>DUEDATE .. FINE TO BE PAID IS SHOWN */ if (issueFilteredResultSet.getString("return_date") != null && (issueFilteredResultSet.getString("return_date").compareTo("") != 0)) { returnDate = format.parse(issueFilteredResultSet.getString("return_date")); } else { String tempDate = format.format(new Date()); returnDate = format.parse(tempDate); if (dueDate.before(returnDate)) // i.e due date before today and book is not returned. flag++; } returnDateJoda = new LocalDate(returnDate); dueDateJoda = new LocalDate(dueDate); } catch (ParseException ex) { Logger.getLogger(EditViewStudent.class.getName()).log(Level.SEVERE, null, ex); } if (dueDate.before(returnDate)) { Days d = Days.daysBetween(dueDateJoda, returnDateJoda); fine += d.getDays(); } if (issueFilteredResultSet.getString("return_date") == null || (issueFilteredResultSet.getString("return_date").compareTo("") == 0)) { currentIssue++; } } /** * setting values in Labels */ issuedFiltered.setText("Total Books Issued : " + totalIssued); returnedFiltered.setText("Total Books Returned : " + returned); if (fine < 0) fine = 0; fineFiltered.setText("Total Fine : " + fine); currentFiltered.setText("Currently issued book count : " + currentIssue); if (flag != 0) { //exceedLabel.setText("* "+ flag +" books have exceeded due date and are not returned. Assuming they are retuned today, total fine is being shown."); } }
From source file:com.nitdlibrary.ReportGenerator.java
/** * This method extracts details from database into result sets and updates fields *//*from w w w . ja v a 2s.c o m*/ private void updateView(int issueKey) throws Exception { DateFormat format = Config.dateFormat; todayLabel.setText("Today's Date : " + (new LocalDate(new java.util.Date())).toString("yyyy-MM-dd")); this.issueID = issueKey; this.library = NITDLibrary.createConnection(); PreparedStatement queryIssue = library.prepareStatement("select * from issue where issue_id = ?"); queryIssue.setInt(1, issueID); issue = queryIssue.executeQuery(); issue.next(); /** * Updating issue related fields */ issueIDLabel.setText((new Integer(issueID).toString())); LocalDate issueDateJoda = new LocalDate(issue.getString("issue_date")); LocalDate returnDateJoda = null; if (issue.getString("return_date") != null) { returnDateJoda = new LocalDate(issue.getString("return_date")); returnDate.setText(returnDateJoda.toString("dd-MM-yyyy")); } else returnDate.setText(null); // System.out.println("RETURN DATE : " + returnDateJoda.toString()); LocalDate dueDateJoda = new LocalDate(issue.getString("due_date")); issueDate.setText(issueDateJoda.toString("dd-MM-yyyy")); dueDate.setText(dueDateJoda.toString("dd-MM-yyyy")); int exceed = Config.daysExceeded(issue.getString("return_date"), issue.getString("due_date")); if (exceed < 0) exceed = 0; exceedSpinner.setValue(exceed); fine.setText((new Integer(exceed * Config.ChARGEPERDAY).toString())); acc = issue.getInt("acc_no"); roll = issue.getInt("issuer_id"); /** * Obtaining result sets for books and student */ ResultSet[] holder = Config.getReportData(acc, roll); books = holder[0]; student = holder[1]; books.next(); student.next(); /** * updating student fields */ fname.setText(student.getString("First Name")); lname.setText(student.getString("Last Name")); contactnumber.setText(student.getString("Contact Number")); email.setText(student.getString("E-Mail")); rollno.setText(student.getString("roll_no")); cardno.setText(student.getString("Card Numbers")); category.setText(student.getString("Category")); programme.setText(student.getString("Programme")); branch.setText(student.getString("Branch")); /** * CHECKING IF STUDENT IS PASSED OUT */ String programmeString = student.getString("Programme"); if (Config.isPassed(programmeString, student.getInt("Year"))) { yearStudent.setText("Passed Out"); } else { yearStudent.setText(student.getString("Year")); // so that when changes are saved data is not lost } Image image = null; try { image = ImageIO.read(new File(student.getString("pic_path"))); } catch (IOException ex) { Logger.getLogger(EditViewStudent.class.getName()).log(Level.SEVERE, null, ex); } Image scaledImage = getScaledImage(image, 168, 130); picLabel.setIcon(new ImageIcon(scaledImage)); /** * Load details for book */ title.setText(books.getString("title")); author1.setText(books.getString("author")); author2.setText(books.getString("author2")); author3.setText(books.getString("author3")); isbn.setText(books.getString("ISBN")); publisher.setText(books.getString("publisher")); edition.setText(books.getString("edition")); price.setText((new Float(books.getFloat("price")).toString())); String[] yearFull = books.getString("year").split("[-]"); year.setText(yearFull[0]); pagination.setText((new Integer(books.getInt("pagination")).toString())); subjectCombo.setText(books.getString("subject")); location.setText(books.getString("location")); accNo.setText(books.getString("acc_no")); switch (books.getInt("status")) { case 0: status.setText("None"); break; case 1: status.setText("Students"); break; case 2: status.setText("Teachers"); break; case 3: status.setText("All"); break; } }
From source file:com.pamarin.income.util.DateUtils.java
private static Date toDateOfWeek(Date date, int index) { LocalDate now = new LocalDate(filterDate(date)); return toStartTime(now.withDayOfWeek(index).toDate()); }
From source file:com.pamarin.income.util.JodaTimeT.java
@Test public void firstDateOfThisWeek() { LocalDate now = new LocalDate(new Date().getTime()); LOG.debug("first date of week --> {}", now.withDayOfWeek(DateTimeConstants.MONDAY)); LOG.debug("last date of week --> {}", now.withDayOfWeek(DateTimeConstants.SUNDAY)); }
From source file:com.qcadoo.mes.productionPerShift.PpsTimeHelper.java
License:Open Source License
public Date findFinishDate(final Entity dailyProgress, Date dateOfDay, Entity order) { DateTime endDate = null;//from w w w.j a va 2 s. co m DateTime dateOfDayDT = new DateTime(dateOfDay, DateTimeZone.getDefault()); DateTime orderStartDate = new DateTime(order.getDateField(OrderFields.START_DATE), DateTimeZone.getDefault()); Entity shiftEntity = dailyProgress.getBelongsToField(DailyProgressFields.SHIFT); Shift shift = new Shift(shiftEntity); List<TimeRange> shiftWorkTime = Lists.newArrayList(); List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList(); if (shift.worksAt(dateOfDay.getDay() == 0 ? 7 : dateOfDay.getDay())) { shiftWorkTime = shift.findWorkTimeAt(new LocalDate(dateOfDay)); } for (TimeRange range : shiftWorkTime) { DateTimeRange dateTimeRange = new DateTimeRange(dateOfDayDT, range); DateTimeRange trimmedRange = dateTimeRange.trimBefore(orderStartDate); if (trimmedRange != null) { shiftWorkDateTime.add(trimmedRange); } } shiftWorkDateTime = manageExceptions(shiftWorkDateTime, shift.getEntity(), dateOfDay); for (DateTimeRange range : shiftWorkDateTime) { if (endDate == null || endDate.isBefore(range.getTo())) { endDate = range.getTo(); } } return endDate.toDate(); }
From source file:com.restservice.database.Transactor.java
License:Open Source License
/** * Returns tweet specified by index//from w w w . ja va 2s. com * * @param tweet * id * @return tweet DTO * @throws SQLException * thrown if a SQL-Error occurs */ public Tweet getTweet(String id) throws SQLException { Tweet tweet = null; try { connect = DriverManager.getConnection(dbUrl); readStatement = connect.prepareStatement(readQuery); readStatement.execute(); prepStatement = connect.prepareStatement("select * from tweets where id = ? LIMIT 1;"); prepStatement.setString(1, id); ResultSet result = prepStatement.executeQuery(); if (result.first()) { tweet = new Tweet(); tweet.setId(id); tweet.setCoordinateLongitude(result.getFloat("coordinates_longitude")); tweet.setCoordinateLatitude(result.getFloat("coordinates_latitude")); tweet.setCreatedAt((new LocalDate(result.getDate("created_at").getTime())).toString()); tweet.setText(result.getString("text")); tweet.setLang(new Language(result.getString("iso_language_code"))); tweet.setRetweetCount(result.getInt("retweet_count")); tweet.setSentiment(new Sentiment(result.getFloat("sentiment"))); tweet.setUserId(result.getString("users_id")); tweet.setRetweetId(result.getString("is_retweet_of_id")); tweet.setReplyId(result.getString("is_reply_to_status_id")); tweet.setSource(result.getString("source")); } result = null; } catch (Exception e) { throw e; } finally { close(); } return tweet; }
From source file:com.roflcode.fitnessChallenge.FetchFitbitActivities.java
License:Apache License
@Override public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider serviceProvider) { logger = serviceProvider.getLoggerService(FetchFitbitActivities.class); logger.debug("get fitbit activities ------------------------------"); String stackmobUserID = request.getParams().get("stackmob_user_id"); String startDateStr = request.getParams().get("start_date"); String endDateStr = request.getParams().get("end_date"); if (endDateStr == "") { endDateStr = startDateStr;// w ww .j a va2 s .c o m } if (stackmobUserID == null || stackmobUserID.isEmpty()) { HashMap<String, String> errParams = new HashMap<String, String>(); errParams.put("error", "stackmobUserID was empty or null"); return new ResponseToProcess(HttpURLConnection.HTTP_BAD_REQUEST, errParams); // http 400 - bad request } FitbitApiClientAgent agent = AgentInitializer.GetInitializedAgent(serviceProvider, stackmobUserID); if (agent == null) { HashMap<String, String> errParams = new HashMap<String, String>(); errParams.put("error", "could not initialize fitbit client agent"); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errParams); // http 500 internal error } HashMap<String, String> credentials = AgentInitializer.GetStoredFitbitCredentials(serviceProvider, stackmobUserID); String fitbitUserID = credentials.get("fitbituserid"); LocalUserDetail user = new LocalUserDetail(stackmobUserID); FitbitUser fitbitUser = new FitbitUser(fitbitUserID); //LocalDate today = new LocalDate(DateTimeZone.UTC); DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/yyyy"); DateTime dt = formatter.parseDateTime(startDateStr); LocalDate startDate = new LocalDate(dt); dt = formatter.parseDateTime(endDateStr); LocalDate endDate = new LocalDate(dt); //TimeZone tz = TimeZone.getTimeZone("GMT-8:00"); //LocalDate today = new LocalDate(DateTimeZone.forTimeZone(tz)); //LocalDate today = new LocalDate(DateTimeZone.forTimeZone(tz)); //LocalDate yesterday = today.minusDays(1); logger.debug("entering date loop " + startDate.toString() + " end: " + endDate.toString()); for (LocalDate date = startDate; date.isBefore(endDate) || date.isEqual(endDate); date = date.plusDays(1)) { logger.debug("date: " + date.toString()); Activities activities; try { activities = agent.getActivities(user, fitbitUser, date); } catch (FitbitAPIException ex) { logger.error("failed to get activities", ex); HashMap<String, String> errParams = new HashMap<String, String>(); errParams.put("error", "could not get activities"); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errParams); // http 500 internal error } ActivitiesSummary summary = activities.getSummary(); // private Integer floors = null; // private Double elevation = null; // private List<ActivityDistance> distances; DataService dataService = serviceProvider.getDataService(); DateMidnight dateMidnight = date.toDateMidnight(); long millis = dateMidnight.getMillis(); List<SMCondition> query; List<SMObject> result; // build a query query = new ArrayList<SMCondition>(); query.add(new SMEquals("theusername", new SMString(stackmobUserID))); query.add(new SMEquals("activity_date", new SMInt(millis))); // execute the query try { boolean newActivity = false; SMValue activityId; result = dataService.readObjects("activity", query); SMObject activityObject; //activity was in the datastore, so update if (result != null && result.size() == 1) { activityObject = result.get(0); List<SMUpdate> update = new ArrayList<SMUpdate>(); update.add(new SMSet("active_score", new SMInt((long) summary.getActiveScore()))); update.add(new SMSet("steps", new SMInt((long) summary.getSteps()))); update.add(new SMSet("floors", new SMInt((long) summary.getFloors()))); update.add(new SMSet("sedentary_minutes", new SMInt((long) summary.getSedentaryMinutes()))); update.add(new SMSet("lightly_active_minutes", new SMInt((long) summary.getLightlyActiveMinutes()))); update.add( new SMSet("fairly_active_minutes", new SMInt((long) summary.getFairlyActiveMinutes()))); update.add(new SMSet("very_active_minutes", new SMInt((long) summary.getVeryActiveMinutes()))); activityId = activityObject.getValue().get("activity_id"); logger.debug("update object"); dataService.updateObject("activity", activityId, update); logger.debug("updated object"); } else { Map<String, SMValue> activityMap = new HashMap<String, SMValue>(); activityMap.put("theusername", new SMString(stackmobUserID)); activityMap.put("activity_date", new SMInt(millis)); activityMap.put("activity_date_str", new SMString(date.toString())); activityMap.put("active_score", new SMInt((long) summary.getActiveScore())); activityMap.put("steps", new SMInt((long) summary.getSteps())); activityMap.put("floors", new SMInt((long) summary.getFloors())); activityMap.put("sedentary_minutes", new SMInt((long) summary.getSedentaryMinutes())); activityMap.put("lightly_active_minutes", new SMInt((long) summary.getLightlyActiveMinutes())); activityMap.put("fairly_active_minutes", new SMInt((long) summary.getFairlyActiveMinutes())); activityMap.put("very_active_minutes", new SMInt((long) summary.getVeryActiveMinutes())); activityObject = new SMObject(activityMap); logger.debug("create object"); activityObject = dataService.createObject("activity", activityObject); logger.debug("created object"); activityId = activityObject.getValue().get("activity_id"); newActivity = true; } } catch (InvalidSchemaException e) { HashMap<String, String> errMap = new HashMap<String, String>(); errMap.put("error", "invalid_schema"); errMap.put("detail", e.toString()); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errMap); // http 500 - internal server error } catch (DatastoreException e) { HashMap<String, String> errMap = new HashMap<String, String>(); errMap.put("error", "datastore_exception"); errMap.put("detail", e.toString()); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errMap); // http 500 - internal server error } catch (Exception e) { HashMap<String, String> errMap = new HashMap<String, String>(); errMap.put("error", "unknown"); errMap.put("detail", e.toString()); return new ResponseToProcess(HttpURLConnection.HTTP_INTERNAL_ERROR, errMap); // http 500 - internal server error } } Map<String, Object> returnMap = new HashMap<String, Object>(); returnMap.put("success?", "think so"); // returnMap.put("activity_id", activityId); // returnMap.put("newActivity", newActivity); //returnMap.put("activitiesJson", activities); logger.debug("completed get activities"); return new ResponseToProcess(HttpURLConnection.HTTP_OK, returnMap); }
From source file:com.sandata.lab.common.utils.data.adapter.CustomJodaDateAdapter.java
License:Open Source License
@Override public LocalDate deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { return new LocalDate(jsonElement.getAsString()); }
From source file:com.sonicle.webtop.core.jooq.LocalDateConverter.java
License:Open Source License
@Override public LocalDate from(Date t) { return (t == null) ? null : new LocalDate(t); }
From source file:com.sonicle.webtop.mail.FolderCache.java
License:Open Source License
private LocalDate getArchivingReferenceDate(Message message) throws MessagingException { java.util.Date date = message.getSentDate(); if (date == null) date = message.getReceivedDate(); return new LocalDate(date); }