List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:elw.web.FormatTool.java
License:Open Source License
public String format(final long dateLong, String pattern, String patternWeek, String patternToday) { final DateTimeFormatter formatter = lookupFormatter(pattern); final DateTimeFormatter formatterToday = lookupFormatter(patternToday); final DateTimeFormatter formatterWeek = lookupFormatter(patternWeek); final DateTime now = new DateTime(System.currentTimeMillis()); final DateTime midnight = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0, 0, 0, 0);// w ww. j av a 2 s . c o m if (midnight.isBefore(dateLong) && midnight.plusDays(1).isAfter(dateLong)) { return formatterToday.print(dateLong); } else if (now.minusDays(7).isBefore(dateLong) && now.plusDays(7).isAfter(dateLong)) { return formatterWeek.print(dateLong); } else { return formatter.print(dateLong); } }
From source file:es.pode.adl.datamodels.datatypes.DateTimeValidator.java
License:Open Source License
/** * Compares two valid data model elements for equality. * /*from w w w .jav a2 s . co m*/ * @param iFirst The first value being compared. * * @param iSecond The second value being compared. * * @param iDelimiters The common set of delimiters associated with the * values being compared. * * @return Returns <code>true</code> if the two values are equal, otherwise * <code>false</code>. */ public boolean compare(String iFirst, String iSecond, Vector iDelimiters) { boolean equal = true; DateTimeFormatter dtp = ISODateTimeFormat.dateTimeParser(); try { // Parse the first string and remove the sub-seconds DateTime dt1 = dtp.parseDateTime(iFirst); dt1 = new DateTime(dt1.getYear(), dt1.getMonthOfYear(), dt1.getDayOfMonth(), dt1.getHourOfDay(), dt1.getMinuteOfHour(), dt1.getSecondOfMinute(), 0); // Parse the second string and remove the sub-seconds DateTime dt2 = dtp.parseDateTime(iSecond); dt2 = new DateTime(dt2.getYear(), dt2.getMonthOfYear(), dt2.getDayOfMonth(), dt2.getHourOfDay(), dt2.getMinuteOfHour(), dt2.getSecondOfMinute(), 0); equal = dt1.equals(dt2); } catch (Exception e) { // String format error -- these cannot be equal equal = false; } return equal; }
From source file:es.ucm.fdi.tutorias.business.boundary.Emails.java
License:Open Source License
private boolean crearArchivoCal(String nombreCalendario, Tutoria tutoria) { String hostEmail = username;/*from ww w.jav a 2s. c o m*/ //Initialize values String calFile = nombreCalendario; ; //start time DateTime comienzo = tutoria.getComienzoTutoria(); java.util.Calendar startCal = java.util.Calendar.getInstance(); startCal.set(comienzo.getYear(), comienzo.getMonthOfYear(), comienzo.getDayOfMonth(), comienzo.getHourOfDay(), comienzo.getMinuteOfHour()); //end time java.util.Calendar endCal = java.util.Calendar.getInstance(); DateTime fin = tutoria.getFinTutoria(); endCal.set(fin.getYear(), fin.getMonthOfYear(), fin.getDayOfMonth(), fin.getHourOfDay(), fin.getMinuteOfHour()); String subject = "Tutora"; String location = "Location - \"Facultad de Informtica-UCM\""; String description = tutoria.getResumenDudas(); net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar(); calendar.getProperties().add(new ProdId("-//ProyectoSI-FdiUcm//iCal4j 1.0//EN")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMdd'T'hhmmss'Z'"); String strDate = sdFormat.format(startCal.getTime()); net.fortuna.ical4j.model.Date startDt = null; try { startDt = new net.fortuna.ical4j.model.Date(strDate, "yyyyMMdd'T'hhmmss'Z'"); } catch (ParseException e) { e.printStackTrace(); return false; } long diff = endCal.getTimeInMillis() - startCal.getTimeInMillis(); int min = (int) (diff / (1000 * 60)); Dur dur = new Dur(0, 0, min, 0); //Creating a meeting event VEvent meeting = new VEvent(startDt, dur, subject); meeting.getProperties().add(new Location(location)); meeting.getProperties().add(new Description()); try { meeting.getProperties().getProperty(Property.DESCRIPTION).setValue(description); } catch (IOException e) { e.printStackTrace(); return false; } catch (URISyntaxException e) { e.printStackTrace(); return false; } catch (ParseException e) { e.printStackTrace(); return false; } try { meeting.getProperties().add(new Organizer("MAILTO:" + hostEmail)); } catch (URISyntaxException e) { e.printStackTrace(); return false; } calendar.getComponents().add(meeting); FileOutputStream fout = null; try { fout = new FileOutputStream(calFile); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } CalendarOutputter outputter = new CalendarOutputter(); outputter.setValidating(false); try { outputter.output(calendar, fout); return true; } catch (IOException e) { e.printStackTrace(); return false; } catch (ValidationException e) { e.printStackTrace(); return false; } }
From source file:etc.HelperUtils.java
License:Apache License
/** * Takes the Timestamp in milis and parses it to the form "yyyy-MM-dd HH:mm" or to "unlimited", if zero * /*from w ww . ja va2 s . c o m*/ * @param ts_Active * the timestamp * @return the parsed timestamp */ public static String parseStringTs(long ts_Active) { if (ts_Active == 0) return "unlimited"; DateTime dt = new DateTime(ts_Active); StringBuilder timeString = new StringBuilder(); // add a leading "0" if the value is under ten timeString.append(dt.getYear()).append("-"); timeString.append(addZero(dt.getMonthOfYear())); timeString.append("-"); timeString.append(addZero(dt.getDayOfMonth())); timeString.append(" "); timeString.append(addZero(dt.getHourOfDay())); timeString.append(":"); timeString.append(addZero(dt.getMinuteOfHour())); return timeString.toString(); }
From source file:eu.cassandra.training.consumption.ConsumptionEventRepo.java
License:Apache License
/** * /* w ww .j av a 2 s .c o m*/ * Function for importing consumption events from an file. * * @param filename * The name of the file that will be exported. * @throws FileNotFoundException */ public void readEventsFile(String filename, Installation installation) throws FileNotFoundException { int startMinute = 0; int endMinute = 0; int counter = 0; DateTime startDateTime = new DateTime(); DateTime endDateTime = new DateTime(); DateTime startDate = new DateTime(); DateTime endDate = new DateTime(); DateTime date = installation.getStartDate(); System.out.println(filename); File file = new File(filename); Scanner scanner = new Scanner(file); String line = scanner.nextLine(); String[] temp = new String[2]; while (scanner.hasNext()) { line = scanner.nextLine(); temp = line.split("-"); startMinute = Integer.parseInt(temp[0]); endMinute = Integer.parseInt(temp[1]); startDateTime = date.plusMinutes(startMinute); endDateTime = date.plusMinutes(endMinute); startDate = new DateTime(startDateTime.getYear(), startDateTime.getMonthOfYear(), startDateTime.getDayOfMonth(), 0, 0); endDate = new DateTime(endDateTime.getYear(), endDateTime.getMonthOfYear(), endDateTime.getDayOfMonth(), 0, 0); if (startDateTime.isAfter(endDateTime) == false) events.add(new ConsumptionEvent(counter++, startDateTime, startDate, endDateTime, endDate)); else System.out.println("Start: " + startDateTime + " End: " + endDateTime); } scanner.close(); analyze(installation.getStartDate(), installation.getEndDate()); }
From source file:eu.itesla_project.cases.EntsoeCaseRepository.java
License:Mozilla Public License
private <R> R scanRepository(DateTime date, CaseType type, Country country, Function<List<ImportContext>, R> handler) { Collection<UcteGeographicalCode> geographicalCodes = country != null ? forCountryHacked(country) : Collections.singleton(UcteGeographicalCode.UX); for (EntsoeFormat format : formats) { Path formatDir = config.getRootDir().resolve(format.getDirName()); if (Files.exists(formatDir)) { Path typeDir = formatDir.resolve(type.name()); if (Files.exists(typeDir)) { Path dayDir = typeDir.resolve(String.format("%04d", date.getYear())) .resolve(String.format("%02d", date.getMonthOfYear())) .resolve(String.format("%02d", date.getDayOfMonth())); if (Files.exists(dayDir)) { List<ImportContext> importContexts = null; for (UcteGeographicalCode geographicalCode : geographicalCodes) { Collection<String> forbiddenFormats = config.getForbiddenFormatsByGeographicalCode() .get(geographicalCode); if (!forbiddenFormats.contains(format.getImporter().getFormat())) { for (int i = 9; i >= 0; i--) { String baseName = String.format( "%04d%02d%02d_%02d%02d_" + type + "%01d_" + geographicalCode.name() + "%01d", date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), date.getDayOfWeek(), i); ReadOnlyDataSource ds = dataSourceFactory.create(dayDir, baseName); if (importContexts == null) { importContexts = new ArrayList<>(); }/*from w ww. j a va2s. c om*/ if (format.getImporter().exists(ds)) { importContexts.add(new ImportContext(format.getImporter(), ds)); } } } } if (importContexts != null) { R result = handler.apply(importContexts); if (result != null) { return result; } } } } } } return null; }
From source file:eu.itesla_project.entsoe.cases.EntsoeCaseRepository.java
License:Mozilla Public License
private <R> R scanRepository(DateTime date, CaseType type, Country country, Function<List<ImportContext>, R> handler) { Collection<EntsoeGeographicalCode> geographicalCodes = country != null ? forCountryHacked(country) : Collections.singleton(EntsoeGeographicalCode.UX); for (EntsoeFormat format : formats) { Path formatDir = config.getRootDir().resolve(format.getDirName()); if (Files.exists(formatDir)) { Path typeDir = formatDir.resolve(type.name()); if (Files.exists(typeDir)) { Path dayDir = typeDir.resolve(String.format("%04d", date.getYear())) .resolve(String.format("%02d", date.getMonthOfYear())) .resolve(String.format("%02d", date.getDayOfMonth())); if (Files.exists(dayDir)) { List<ImportContext> importContexts = null; for (EntsoeGeographicalCode geographicalCode : geographicalCodes) { Collection<String> forbiddenFormats = config.getForbiddenFormatsByGeographicalCode() .get(geographicalCode); if (!forbiddenFormats.contains(format.getImporter().getFormat())) { for (int i = 9; i >= 0; i--) { String baseName = String.format( "%04d%02d%02d_%02d%02d_" + type + "%01d_" + geographicalCode.name() + "%01d", date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), date.getDayOfWeek(), i); ReadOnlyDataSource ds = dataSourceFactory.create(dayDir, baseName); if (importContexts == null) { importContexts = new ArrayList<>(); }// w w w .j a v a 2 s. com if (format.getImporter().exists(ds)) { importContexts.add(new ImportContext(format.getImporter(), ds)); } } } } if (importContexts != null) { R result = handler.apply(importContexts); if (result != null) { return result; } } } } } } return null; }
From source file:fi.craplab.roameo.ui.StatisticsWeekFragment.java
License:Open Source License
private void setupData() { DateTime dateTime = getFirstDayOfWeek(); DebugLog.d(TAG, String.format(Locale.US, "Setting up data for week %2d %d starting %s", mWeekNumber, mWeekYear, dateTime));/*from w w w. ja va 2 s.c o m*/ for (int day = 0; day < DateTimeConstants.DAYS_PER_WEEK; day++) { DateTime dt = dateTime.plusDays(day); long steps = CallSession.getStepsForDay(dt.getMillis()); float duration = CallSession.getDurationsForDay(dt.getMillis()) / 1000; float pace = (duration > 0) ? (steps / (duration / 60f)) : 0.0f; mStepValues.add(new PointValue(day, steps)); mDurationValues.add(new PointValue(day, duration)); mPaceValues.add(new PointValue(day, pace)); mDayNameValues.add(day, new AxisValue(day).setLabel(dt.dayOfWeek().getAsShortText())); mDateValues.add(day, new AxisValue(day) .setLabel(String.format(Locale.US, "%02d/%02d", dt.getDayOfMonth(), dt.getMonthOfYear()))); } }
From source file:fi.craplab.roameo.ui.view.ExportDatePickerDialog.java
License:Open Source License
public ExportDatePickerDialog(@NonNull Context context, @NonNull OnDateSetListener listener, int datePickerType, DateTime dateTime) { mDialog = new DatePickerDialog(context, this, dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth()); mListener = listener;/*from w w w . j a v a2 s . c o m*/ mPickerType = datePickerType; }
From source file:gobblin.ingestion.google.DayPartitioner.java
License:Apache License
@Override public GenericRecord partitionForRecord(GenericRecord record) { GenericRecord partition = new GenericData.Record(_partitionSchema); String dateString = record.get(_dateColumn).toString(); DateTime date = _dateFormatter.parseDateTime(dateString); if (_withPrefix) { if (_withColumnNames) { partition.put(PARTITION_COLUMN_PREFIX, PARTITION_COLUMN_PREFIX + "=" + _prefix); } else {// w w w . j a v a 2 s . c o m partition.put(PARTITION_COLUMN_PREFIX, _prefix); } } if (_withColumnNames) { partition.put(PARTITION_COLUMN_YEAR, PARTITION_COLUMN_YEAR + "=" + date.getYear()); partition.put(PARTITION_COLUMN_MONTH, PARTITION_COLUMN_MONTH + "=" + date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, PARTITION_COLUMN_DAY + "=" + date.getDayOfMonth()); } else { partition.put(PARTITION_COLUMN_YEAR, date.getYear()); partition.put(PARTITION_COLUMN_MONTH, date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, date.getDayOfMonth()); } return partition; }