List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.sheepdog.mashmesh.models.VolunteerProfile.java
License:Apache License
public void addAppointmentTime(RideRequest rideRequest, DateTime departureTime, DateTime arrivalTime) { Duration commuteDuration = new Duration(departureTime, arrivalTime); DateTime startTime = departureTime; DateTime endTime = arrivalTime.plus(commuteDuration); AppointmentPeriod appointmentTime = new AppointmentPeriod(); appointmentTime.rideRequestId = rideRequest.getId(); appointmentTime.startTimeMillis = startTime.getMillis(); appointmentTime.endTimeMillis = endTime.getMillis(); appointmentTimes.add(appointmentTime); }
From source file:com.sifiso.dvs.util.PhotoUtil.java
public ResponseDTO downloadPhotos(HttpServletRequest request, PlatformUtil platformUtil) throws FileUploadException { logger.log(Level.INFO, "######### starting PHOTO DOWNLOAD process\n\n"); ResponseDTO resp = new ResponseDTO(); InputStream stream = null;// ww w . j av a2 s . c om File rootDir; try { rootDir = dvsProperties.getImageDir(); logger.log(Level.INFO, "rootDir - {0}", rootDir.getAbsolutePath()); if (!rootDir.exists()) { rootDir.mkdir(); } } catch (Exception ex) { logger.log(Level.SEVERE, "Properties file problem", ex); resp.setMessage("Server file unavailable. Please try later"); resp.setStatusCode(114); return resp; } PhotoUploadDTO dto = null; Gson gson = new Gson(); File doctorFileDir = null, surgeryDir = null; try { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { FileItemStream item = iter.next(); String name = item.getFieldName(); stream = item.openStream(); if (item.isFormField()) { if (name.equalsIgnoreCase("JSON")) { String json = Streams.asString(stream); if (json != null) { logger.log(Level.INFO, "picture with associated json: {0}", json); dto = gson.fromJson(json, PhotoUploadDTO.class); if (dto != null) { surgeryDir = createSurgeryFileDirectory(rootDir, surgeryDir, dto.getSurgeryID()); if (dto.getDoctorID() > 0) { doctorFileDir = createDoctorDirectory(surgeryDir, doctorFileDir, dto.getDoctorID()); } } } else { logger.log(Level.WARNING, "JSON input seems pretty fucked up! is NULL.."); } } } else { File imageFile = null; if (dto == null) { continue; } DateTime dt = new DateTime(); String fileName = ""; if (dto.isIsFullPicture()) { fileName = "f" + dt.getMillis() + ".jpg"; } else { fileName = "t" + dt.getMillis() + ".jpg"; } if (dto.getPatientfileID() != null) { if (dto.isIsFullPicture()) { fileName = "f" + dto.getPatientfileID() + ".jpg"; } else { fileName = "t" + dto.getPatientfileID() + ".jpg"; } } // switch (dto.getPictureType()) { case PhotoUploadDTO.FILES_DOCTOR: imageFile = new File(doctorFileDir, fileName); break; case PhotoUploadDTO.FILES_SURGERY: imageFile = new File(surgeryDir, fileName); } writeFile(stream, imageFile); resp.setStatusCode(0); resp.setMessage("Photo downloaded from mobile app "); //add database System.out.println("filepath: " + imageFile.getAbsolutePath()); //create uri /*int index = imageFile.getAbsolutePath().indexOf("monitor_images"); if (index > -1) { String uri = imageFile.getAbsolutePath().substring(index); System.out.println("uri: " + uri); dto.setUri(uri); } dto.setDateUploaded(new Date()); if (dto.isIsFullPicture()) { dto.setThumbFlag(null); } else { dto.setThumbFlag(1); } dataUtil.addPhotoUpload(dto);*/ } } } catch (FileUploadException | IOException | JsonSyntaxException ex) { logger.log(Level.SEVERE, "Servlet failed on IOException, images NOT uploaded", ex); throw new FileUploadException(); } return resp; }
From source file:com.sifiso.yazisa.util.PhotoUtil.java
public ResponseDTO downloadPhotos(HttpServletRequest request, PlatformUtil platformUtil) throws FileUploadException { logger.log(Level.INFO, "######### starting PHOTO DOWNLOAD process\n\n"); ResponseDTO resp = new ResponseDTO(); InputStream stream = null;/*from w w w. jav a 2s .c o m*/ File rootDir; try { rootDir = YazisaProperties.getImageDir(); logger.log(Level.INFO, "rootDir - {0}", rootDir.getAbsolutePath()); if (!rootDir.exists()) { rootDir.mkdir(); } } catch (Exception ex) { logger.log(Level.SEVERE, "Properties file problem", ex); resp.setMessage("Server file unavailable. Please try later"); resp.setStatusCode(114); return resp; } PhotoUploadDTO dto = null; Gson gson = new Gson(); File schoolDir = null, classDir = null, parentDir = null, teacherDir = null, studentDir = null; try { ServletFileUpload upload = new ServletFileUpload(); FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { FileItemStream item = iter.next(); String name = item.getFieldName(); stream = item.openStream(); if (item.isFormField()) { if (name.equalsIgnoreCase("JSON")) { String json = Streams.asString(stream); if (json != null) { logger.log(Level.INFO, "picture with associated json: {0}", json); dto = gson.fromJson(json, PhotoUploadDTO.class); if (dto != null) { if (dto.getSchoolID() > 0) { schoolDir = createSchoolDirectory(rootDir, schoolDir, dto.getSchoolID()); } if (dto.getClassID() > 0) { classDir = createClassDirectory(schoolDir, classDir, dto.getClassID()); } if (dto.getParentID() > 0) { parentDir = createParentDirectory(schoolDir, parentDir); } if (dto.getTeacherID() > 0) { teacherDir = createTeacherDirectory(schoolDir, teacherDir); } if (dto.getStudentID() > 0) { studentDir = createStudentDirectory(rootDir, studentDir); } } } else { logger.log(Level.WARNING, "JSON input seems pretty fucked up! is NULL.."); } } } else { File imageFile = null; if (dto == null) { continue; } DateTime dt = new DateTime(); String fileName = ""; if (dto.isIsFullPicture()) { fileName = "f" + dt.getMillis() + ".jpg"; } else { fileName = "t" + dt.getMillis() + ".jpg"; } if (dto.getSchoolID() != null) { if (dto.isIsFullPicture()) { fileName = "f" + dto.getSchoolID() + ".jpg"; } else { fileName = "t" + dto.getSchoolID() + ".jpg"; } } if (dto.getSchoolID() != null) { if (dto.getTeacherID() != null) { if (dto.isIsFullPicture()) { fileName = "f" + dto.getTeacherID() + ".jpg"; } else { fileName = "t" + dto.getTeacherID() + ".jpg"; } } } if (dto.getSchoolID() != null) { if (dto.getClassID() != null) { if (dto.isIsFullPicture()) { fileName = "f" + dto.getClassID() + "-" + new Date().getYear() + ".jpg"; } else { fileName = "t" + dto.getClassID() + "-" + new Date().getYear() + ".jpg"; } } } if (dto.getSchoolID() != null) { if (dto.getParentID() != null) { if (dto.isIsFullPicture()) { fileName = "f" + dto.getParentID() + ".jpg"; } else { fileName = "t" + dto.getParentID() + ".jpg"; } } } if (dto.getStudentID() != null) { if (dto.isIsFullPicture()) { fileName = "f" + dto.getStudentID() + ".jpg"; } else { fileName = "t" + dto.getStudentID() + ".jpg"; } } // switch (dto.getPictureType()) { case PhotoUploadDTO.SCHOOL_IMAGE: imageFile = new File(schoolDir, fileName); break; case PhotoUploadDTO.CLASS_IMAGE: imageFile = new File(classDir, fileName); break; case PhotoUploadDTO.PARENT_IMAGE: imageFile = new File(parentDir, fileName); break; case PhotoUploadDTO.STUDENT_IMAGE: imageFile = new File(studentDir, fileName); break; } writeFile(stream, imageFile); resp.setStatusCode(0); resp.setMessage("Photo downloaded from mobile app "); //add database System.out.println("filepath: " + imageFile.getAbsolutePath()); //create uri /*int index = imageFile.getAbsolutePath().indexOf("monitor_images"); if (index > -1) { String uri = imageFile.getAbsolutePath().substring(index); System.out.println("uri: " + uri); dto.setUri(uri); } dto.setDateUploaded(new Date()); if (dto.isIsFullPicture()) { dto.setThumbFlag(null); } else { dto.setThumbFlag(1); } dataUtil.addPhotoUpload(dto);*/ } } } catch (FileUploadException | IOException | JsonSyntaxException ex) { logger.log(Level.SEVERE, "Servlet failed on IOException, images NOT uploaded", ex); throw new FileUploadException(); } return resp; }
From source file:com.simplymeasured.hive.UDFISO8601ToTimestamp.java
License:Apache License
public long evaluate(String iso8601Date) { DateTime dateTime = new DateTime(iso8601Date, DateTimeZone.UTC); return dateTime.getMillis() / 1000; }
From source file:com.soen.hasslefree.models.PhysicianAvailability.java
public boolean generateTimeSlots(DateTime startTime, DateTime endTime, int dropInDurationInMinutes) { MutableDateTime slotStatTime = new MutableDateTime(); MutableDateTime slotEndTime = new MutableDateTime(); long availabilityStartTimeInMillis = startTime.getMillis(); long availabilityEndTimeInMillis = startTime.getMillis(); long availableDuration = availabilityEndTimeInMillis - availabilityStartTimeInMillis; long slotDuration = dropInDurationInMinutes * 60 * 1000; // 20 min * 60 sec * 1000 millisecond ArrayList<RoomTimeSlot> roomSlots = RoomTimeSlot.getFilteredAvailableRoomSlotsForDate(startTime, endTime); if (availableDuration > 0) { long currentSlotStartTime = availabilityStartTimeInMillis; boolean stopSlicing = false; while (!stopSlicing) { //<editor-fold defaultstate="collapsed" desc="new PhysicianTimeSlot "> int roomSlotIndex = hasFoundFreeRoomSlot(currentSlotStartTime, roomSlots); if (roomSlotIndex < 0) { return false; } else { PhysicianTimeSlot newTimeSlot = new PhysicianTimeSlot(); slotStatTime.setMillis(currentSlotStartTime); slotEndTime.setMillis(currentSlotStartTime + slotDuration); newTimeSlot.setStartTime(slotStatTime.toDateTime()); newTimeSlot.setEndTime(slotEndTime.toDateTime()); newTimeSlot.setIsAvailable(true); newTimeSlot.setPhysicianAvailability(this); newTimeSlot.setRelatedPhysician(this.relatedPhysician); RoomTimeSlot roomTime = roomSlots.get(roomSlotIndex); newTimeSlot.setRelatedRoomTimeSlot(roomTime); roomTime.setPhysicianTimeSlot(newTimeSlot); roomTime.setIsAvailable(false); //</editor-fold> this.physicianTimeSlots.add(newTimeSlot); availableDuration = availableDuration - slotDuration; currentSlotStartTime = currentSlotStartTime + slotDuration; if (availableDuration < slotDuration) { // I removed = because I want to add the last slot to the time slots. stopSlicing = true;/*from w w w. jav a 2 s. co m*/ } } } } ObjectDao physicianAvailabilityDao = new ObjectDao(); reserveRoomSlot(roomSlots); physicianAvailabilityDao.addOrUpdateObject(this); return true; }
From source file:com.soen.hasslefree.models.Room.java
public void generateTimeSlots(DateTime clinicStartTime, DateTime clinicEndTime, int dropInDurationInMinutes) { MutableDateTime slotStatTime = new MutableDateTime(); MutableDateTime slotEndTime = new MutableDateTime(); //ArrayList<ClinicHours> clinicHoursList = ClinicHours.getAllClinicHours(); // ClinicHours clinicHours = clinicHoursList.get(0); long availabilityStartTime = clinicStartTime.getMillis(); long availabilityEndTime = clinicEndTime.getMillis(); long availableDuration = availabilityEndTime - availabilityStartTime; long slotDuration = dropInDurationInMinutes * 60 * 1000; // dropIn Duration min * 60 sec * 1000 millisecond if (availableDuration > 0) { long currentSlotStartTime = availabilityStartTime; boolean stopSlicing = false; while (!stopSlicing) { //<editor-fold defaultstate="collapsed" desc="new RoomTimeSlot "> RoomTimeSlot newTimeSlot = new RoomTimeSlot(); slotStatTime.setMillis(currentSlotStartTime); slotEndTime.setMillis(currentSlotStartTime + slotDuration); newTimeSlot.setStartTime(slotStatTime.toDateTime()); newTimeSlot.setEndTime(slotEndTime.toDateTime()); newTimeSlot.setIsAvailable(true); newTimeSlot.setRelatedRoom(this); //</editor-fold> this.roomTimeSlots.add(newTimeSlot); availableDuration = availableDuration - slotDuration; currentSlotStartTime = currentSlotStartTime + slotDuration; if (availableDuration < slotDuration) { // I ti should be smaller than only to add the last slot to the time slots. stopSlicing = true;/*from w w w. j a v a 2 s .c o m*/ } } } }
From source file:com.sonicle.webtop.core.jooq.DateTimeConverter.java
License:Open Source License
@Override public Timestamp to(DateTime u) { return (u == null) ? null : new Timestamp(u.getMillis()); }
From source file:com.sos.hibernate.classes.UtcTimeHelper.java
License:Apache License
public static String convertTimeZonesToString(String dateFormat, String fromTimeZone, String toTimeZone, DateTime fromDateTime) {/*from w w w . j a v a 2 s .c o m*/ DateTimeZone fromZone = DateTimeZone.forID(fromTimeZone); DateTimeZone toZone = DateTimeZone.forID(toTimeZone); DateTime dateTime = new DateTime(fromDateTime); dateTime = dateTime.withZoneRetainFields(fromZone); DateTime toDateTime = new DateTime(dateTime).withZone(toZone); DateTimeFormatter oFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'H:mm:ss.SSSZ"); DateTimeFormatter oFormatter2 = DateTimeFormat.forPattern(dateFormat); DateTime newDate = oFormatter.withOffsetParsed().parseDateTime(toDateTime.toString()); return oFormatter2.withZone(toZone).print(newDate.getMillis()); }
From source file:com.sos.hibernate.classes.UtcTimeHelper.java
License:Apache License
public static Date convertTimeZonesToDate(String fromTimeZone, String toTimeZone, DateTime fromDateTime) { if (fromDateTime == null) { return null; }/*w ww.j a v a2s .c o m*/ DateTimeZone fromZone = DateTimeZone.forID(fromTimeZone); DateTimeZone toZone = DateTimeZone.forID(toTimeZone); DateTime dateTime = new DateTime(fromDateTime); dateTime = dateTime.withZoneRetainFields(fromZone); DateTime toDateTime = new DateTime(dateTime).withZone(toZone); DateTimeFormatter oFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'H:mm:ss.SSSZ"); DateTimeFormatter oFormatter2 = DateTimeFormat.forPattern("yyyy-MM-dd H:mm:ss.ss"); DateTime newDate = oFormatter.withOffsetParsed().parseDateTime(toDateTime.toString()); try { return new SimpleDateFormat("yyyy-MM-dd H:mm:ss.ss") .parse(oFormatter2.withZone(toZone).print(newDate.getMillis())); } catch (ParseException e) { e.printStackTrace(); return null; } }
From source file:com.splicemachine.db.iapi.types.SQLTimestamp.java
License:Apache License
/** * Get the value field. We instantiate the field * on demand.// ww w. j a v a 2 s . c o m * * @return The value field. */ public Timestamp getTimestamp(java.util.Calendar cal) { if (isNull()) return null; Timestamp t = null; if (cal == null) { int year = SQLDate.getYear(encodedDate); if (year < SQLDate.JODA_CRUSH_YEAR) { t = computeGregorianCalendarTimestamp(year); } else { try { DateTime dt = createDateTime(); t = new Timestamp(dt.getMillis()); } catch (Exception e) { t = computeGregorianCalendarTimestamp(year); } } } else { setCalendar(cal); t = new Timestamp(cal.getTimeInMillis()); } t.setNanos(nanos); return t; }