List of usage examples for org.joda.time DateTime getYear
public int getYear()
From source file:gobblin.ingestion.google.webmaster.GoogleWebmasterDayPartitioner.java
License:Apache License
@Override public GenericRecord partitionForRecord(GenericRecord record) { GenericRecord partition = new GenericData.Record(_partitionSchema); String dateString = record.get(DATE_COLUMN).toString(); DateTime date = GoogleWebmasterExtractor.dateFormatter.parseDateTime(dateString); if (_withPrefix) { if (_withColumnNames) { partition.put(PARTITION_COLUMN_PREFIX, PARTITION_COLUMN_PREFIX + "=" + _prefix); } else {// www. j a va 2s. 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; }
From source file:gobblin.util.TimeRangeChecker.java
License:Apache License
/** * Checks if a specified time is on a day that is specified the a given {@link List} of acceptable days, and that the * hours + minutes of the specified time fall into a range defined by startTimeStr and endTimeStr. * * @param days is a {@link List} of days, if the specified {@link DateTime} does not have a day that falls is in this * {@link List} then this method will return false. * @param startTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of * the pattern defined by {@link #HOUR_MINUTE_FORMAT}. * @param endTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of * the pattern defined by {@link #HOUR_MINUTE_FORMAT}. * @param currentTime is a {@link DateTime} for which this method will check if it is in the given {@link List} of * days and falls into the time range defined by startTimeStr and endTimeStr. * * @return true if the given time is in the defined range, false otherwise. *///from ww w .j av a 2 s .c o m public static boolean isTimeInRange(List<String> days, String startTimeStr, String endTimeStr, DateTime currentTime) { if (!Iterables.any(days, new AreDaysEqual(DAYS_OF_WEEK.get(currentTime.getDayOfWeek())))) { return false; } DateTime startTime = null; DateTime endTime = null; try { startTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(startTimeStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "startTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e); } try { endTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(endTimeStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "endTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e); } startTime = startTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth()); endTime = endTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth()); Interval interval = new Interval(startTime.getMillis(), endTime.getMillis(), DATE_TIME_ZONE); return interval.contains(currentTime.getMillis()); }
From source file:google.registry.model.common.TimeOfYear.java
License:Open Source License
/** Get the first {@link DateTime} with this month/day/millis that is at or after the start. */ public DateTime getNextInstanceAtOrAfter(DateTime start) { DateTime withSameYear = getDateTimeWithYear(start.getYear()); return isAtOrAfter(withSameYear, start) ? withSameYear : withSameYear.plusYears(1); }
From source file:google.registry.model.common.TimeOfYear.java
License:Open Source License
/** Get the first {@link DateTime} with this month/day/millis that is at or before the end. */ public DateTime getLastInstanceBeforeOrAt(DateTime end) { DateTime withSameYear = getDateTimeWithYear(end.getYear()); return isBeforeOrAt(withSameYear, end) ? withSameYear : withSameYear.minusYears(1); }
From source file:gov.usgs.anss.query.filefactory.SacHeaders.java
License:Open Source License
public static SacTimeSeries setEventHeader(SacTimeSeries sac, DateTime eventOrigin, Double eventLat, Double eventLon, Double eventDepth, Double eventMag, int sacMagType, int sacEventType) { if (eventLat == null) { eventLat = -12345.0;//from w w w .j a v a 2s. c o m } if (eventLon == null) { eventLon = -12345.0; } if (eventDepth == null) { eventDepth = -12345.0; } if (eventMag == null) { eventMag = -12345.0; } // SAC stores year day (nzjday) but not month and day. DateTime start = new DateTime(sac.nzyear, 1, 1, sac.nzhour, sac.nzmin, sac.nzsec, sac.nzmsec, DateTimeZone.UTC); start = start.withDayOfYear(sac.nzjday); double timeDiff = (start.getMillis() - eventOrigin.getMillis()) / 1000.0d; sac.nzyear = eventOrigin.getYear(); sac.nzjday = eventOrigin.getDayOfYear(); sac.nzhour = eventOrigin.getHourOfDay(); sac.nzmin = eventOrigin.getMinuteOfHour(); sac.nzsec = eventOrigin.getSecondOfMinute(); sac.nzmsec = eventOrigin.getMillisOfSecond(); sac.b = sac.b + timeDiff; sac.e = sac.e + timeDiff; sac.iztype = SacTimeSeries.IO; sac.evla = eventLat; sac.evlo = eventLon; sac.evdp = eventDepth; sac.mag = eventMag; sac.imagtyp = sacMagType; sac.ievtyp = sacEventType; sac.lcalda = 1; return sac; }
From source file:gt.org.ms.controller.personas.handlers.validations.DatosPersonaValidation.java
@Override public void validate(final T persona, ValidationRequestContext ctx) { if (persona.getRegistroLaboral().isComisionado() && isNull(persona.getRegistroLaboral().getFkComunidadComisionado())) { throw ExceptionsManager.newValidationException("unidad_notificadora_comisionado", "Debe indicar una unidad notificadora para comisionado!"); }/*w ww . j a v a2 s .c o m*/ ValidationException ex = new ValidationException(new ArrayList<ValidationError>()); if (!persona.isLector()) { if (isNull(persona.getFkNacionalidad())) { throw ExceptionsManager.newValidationException("nacionalidad", "Nacionadlidad es requerida!"); } if (isNull(persona.getFkMunicipioNacimiento())) { throw ExceptionsManager.newValidationException("invalid_lugar_nacimiento", new String[] { "lugar_nac_requerido,Lugar de nacimiento es requerido!" }); } if (isNull(persona.getFechaNacimiento())) { throw ExceptionsManager.newValidationException("invalid_fecha_nacimiento", new String[] { "feha_nac_requerido,Fecha de nacimiento es requerido!" }); } if (!isNull(persona.getFechaNacimiento())) { DateTime f = new DateTime(persona.getFechaNacimiento()); if (f.getYear() >= DateTime.now().getYear()) { ex.getErrors().add(new ValidationError("fecha_nacimiento", "Solo se soportan fechas anteriores al ao actual!")); } else { int diff = DateTime.now().getYear() - f.getYear(); if (diff < 18) { ex.getErrors().add(new ValidationError("fecha_nacimiento", "Solo se permiten personas de 18 aos en adelante!")); } } if (!ex.getErrors().isEmpty()) { throw ex; } } } else { if (isNull(persona.getFkMunicipioNacimientoNombre())) { throw ExceptionsManager.newValidationException("invalid_lugar_nacimiento", new String[] { "lugar_nac_requerido,Lugar de nacimiento es requerido!" }); } if (isNull(persona.getFkNacionalidadNombre())) { throw ExceptionsManager.newValidationException("invalid_lugar_nacimiento", new String[] { "lugar_nac_requerido,Lugar de nacimiento es requerido!" }); } if (isNull(persona.getFechaNacimientoTexto())) { throw ExceptionsManager.newValidationException("invalid_fecha_nacimiento", new String[] { "feha_nac_requerido,Fecha de nacimiento es requerido!" }); } else { try { EntitiesHelper.parseFechaDPI(persona.getFechaNacimientoTexto()); } catch (Exception e) { e.printStackTrace(System.err); throw ExceptionsManager.newValidationException("invalid_fecha_nacimiento", new String[] { "feha_nac_invalido,Fecha de nacimiento es invalida!" }); } } } }
From source file:Implement.Service.CommonServiceImpl.java
@Override public String getToDateInMillisecond() { DateTime toDateObj = new DateTime(); Date result = new Date(toDateObj.getYear() - 1900, toDateObj.getMonthOfYear() - 1, toDateObj.getDayOfMonth());/*from w w w. ja v a2 s. c o m*/ return String.valueOf(result.getTime() + Long.valueOf("86400000")); }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public String getProviderTrippDash(int providerID) { DateTime toDateObj = new DateTime(); Date result = new Date(toDateObj.getYear() - 1900, toDateObj.getMonthOfYear() - 1, toDateObj.getDayOfMonth());/* w w w. j av a2s . c o m*/ long currentTime = Long.valueOf(result.getTime() + Long.valueOf("86400000")); long last30Day = currentTime - Long.valueOf("2592000000"); return gson.toJson(providerDAO.getProviderTrippDash(providerID, currentTime, last30Day)); }
From source file:influent.server.dataaccess.DataAccessHelper.java
License:MIT License
public static String format(DateTime dateTime) { if (dateTime == null) { return null; }/* ww w . j ava2 s . co m*/ StringBuilder s = new StringBuilder(10); s.append(dateTime.getYear()); s.append('-'); pad00(dateTime.getMonthOfYear(), s); s.append('-'); pad00(dateTime.getDayOfMonth(), s); s.append(' '); pad00(dateTime.getHourOfDay(), s); s.append(':'); pad00(dateTime.getMinuteOfHour(), s); s.append(':'); pad00(dateTime.getSecondOfMinute(), s); s.append('.'); int ms = dateTime.getMillisOfSecond(); if (ms < 100) { s.append('0'); } pad00(ms, s); return s.toString(); }
From source file:influent.server.rest.BigChartResource.java
License:MIT License
@Post("json") public Map<String, ChartData> getBigChartData(String jsonData) { try {/* w ww . ja va2 s . com*/ JSONProperties request = new JSONProperties(jsonData); final String focusContextId = request.getString("focuscontextid", null); final String sessionId = request.getString("sessionId", null); if (!GuidValidator.validateGuidString(sessionId)) { throw new ResourceException(Status.CLIENT_ERROR_EXPECTATION_FAILED, "sessionId is not a valid UUID"); } DateTime startDate = null; try { startDate = DateTimeParser.parse(request.getString("startDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "BigChartResource: An illegal argument was passed into the 'startDate' parameter."); } DateTime endDate = null; try { endDate = DateTimeParser.parse(request.getString("endDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "BigChartResource: An illegal argument was passed into the 'endDate' parameter."); } List<String> focusIds = new LinkedList<String>(); Iterable<String> focusIter = request.getStrings("focusId"); for (String entityId : focusIter) { List<String> entities = new ArrayList<String>(); InfluentId id = InfluentId.fromInfluentId(entityId); // Point account owners and summaries to their owner account if (id.getIdClass() == InfluentId.ACCOUNT_OWNER || id.getIdClass() == InfluentId.CLUSTER_SUMMARY) { entities.add(InfluentId.fromNativeId(InfluentId.ACCOUNT, id.getIdType(), id.getNativeId()) .toString()); } else if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { // group cluster for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entities.add(sId); } } } else { entities.add(entityId); } } else { entities.add(entityId); } for (String fid : entities) { if (!focusIds.contains(fid)) { focusIds.add(fid); } } } final Double focusMaxDebitCredit = request.getDouble("focusMaxDebitCredit", null); final Integer width = request.getInteger("width", 145); final Integer height = request.getInteger("height", 60); List<Properties> entityArray = Lists.newArrayList(request.getPropertiesSets("entities")); Map<String, ChartData> infoList = new HashMap<String, ChartData>(entityArray.size()); /// TODO : make this date range sanity check better if (startDate.getYear() < 1900 || startDate.getYear() > 9999) { MutableDateTime msdt = new MutableDateTime(startDate); msdt.setYear(2007); startDate = msdt.toDateTime(); logger.warn("Invalid start date passed from UI, setting to default"); } if (endDate.getYear() < 1900 || endDate.getYear() > 9999) { MutableDateTime medt = new MutableDateTime(endDate); medt.setYear(2013); endDate = medt.toDateTime(); logger.warn("Invalid end date passed from UI, setting to default"); } FL_DateRange dateRange = DateRangeBuilder.getBigChartDateRange(startDate, endDate); // compute an individual chart for each entity received for (Properties entityRequest : entityArray) { final String entityId = entityRequest.getString("dataId", null); final String entityContextId = entityRequest.getString("contextId", null); List<String> entityIds = new ArrayList<String>(); // Check to see if this entityId belongs to a group cluster. InfluentId id = InfluentId.fromInfluentId(entityId); if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { // group cluster for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entityIds.add(sId); } } } else { entityIds.add(entityId); } } else { entityIds.add(entityId); } ChartHash hash = new ChartHash(entityIds, startDate, endDate, focusIds, focusMaxDebitCredit, dateRange.getNumBins().intValue(), width, height, entityContextId, focusContextId, sessionId, contextCache); ChartData chartData = chartBuilder.computeChart(dateRange, entityIds, focusIds, entityContextId, focusContextId, sessionId, dateRange.getNumBins().intValue(), hash); infoList.put(entityId, //memberIds.get(0), chartData); } return infoList; } catch (AvroRemoteException e) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Data access error.", e); } catch (JSONException je) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "JSON parse error.", je); } }