Java Code Examples for org.joda.time.LocalDate#fromDateFields()

The following examples show how to use org.joda.time.LocalDate#fromDateFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EthController.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@RequestMapping("/tx/cnt_static")
public ResponseVo<Map<String, Long>> transactionStatic() {
    Date from = LocalDate.now().plusDays(-15).toDate();
    Date to = LocalDate.now().toDate();
    List<DayCount> dayCounts = ethService.countTransactionByTimestamp(from, to);
    Map<String, Long> dayCountMap = dayCounts.stream()
        .collect(Collectors.toMap(DayCount::getDay, DayCount::getCount));

    LocalDate fromLocalDate = LocalDate.fromDateFields(from);
    LocalDate toLocalDate = LocalDate.fromDateFields(to);
    while (fromLocalDate.isBefore(toLocalDate)) {
        dayCountMap.putIfAbsent(DateUtils.toDay(fromLocalDate.toDate()), 0L);
        fromLocalDate = fromLocalDate.plusDays(1);
    }

    ResponseVo<Map<String, Long>> result = new ResponseVo<>();
    result.setData(new TreeMap<>(dayCountMap));

    return result;
}
 
Example 2
Source File: YouTubeSubscriptionServiceImpl.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void subscribe(YouTubeChannel channel) {
    LocalDate now = LocalDate.now();
    LocalDate expiredAt = channel.getExpiresAt() != null
            ? LocalDate.fromDateFields(channel.getExpiresAt())
            : LocalDate.now();
    if (now.isBefore(expiredAt)) {
        return;
    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("hub.callback", String.format("%s/api/public/youtube/callback/publish?secret=%s&channel=%s",
            commonProperties.getBranding().getWebsiteUrl(),
            apiProperties.getYouTube().getPubSubSecret(),
            CommonUtils.urlEncode(channel.getChannelId())));
    map.add("hub.topic", CHANNEL_RSS_ENDPOINT + channel.getChannelId());
    map.add("hub.mode", "subscribe");
    map.add("hub.verify", "async");
    map.add("hub.verify_token", apiProperties.getYouTube().getPubSubSecret());
    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);

    ResponseEntity<String> response = restTemplate.postForEntity(PUSH_ENDPOINT, request, String.class);
    if (!response.getStatusCode().is2xxSuccessful()) {
        throw new IllegalStateException("Could not subscribe to " + channel.getChannelId());
    }
}
 
Example 3
Source File: CassandraPreparedStatement.java    From cassandra-jdbc-driver with Apache License 2.0 5 votes vote down vote up
@Override
protected void setParameter(int paramIndex, Object paramValue) throws SQLException {
    String typeName = parameterMetaData.getParameterTypeName(paramIndex);
    Class javaClass = getDataTypeMappings().javaTypeFor(typeName);

    boolean replaceNullValue = this.cqlStmt.getConfiguration().replaceNullValue();

    if (javaClass != null) {
        paramValue = getDataTypeConverters().convert(paramValue, javaClass, replaceNullValue);
        // time is mapped by the driver to a primitive long, representing the number of nanoseconds since midnight
        if (CassandraDataType.TIME.getTypeName().equals(typeName) && paramValue instanceof Time) {
            Time time = (Time) paramValue;
            paramValue = new LocalTime(time).getMillisOfDay() * 1000000L;
        } else if (CassandraDataType.DATE.getTypeName().equals(typeName)
                && paramValue instanceof Date) {
            LocalDate localDate = LocalDate.fromDateFields((Date) paramValue);
            paramValue = com.datastax.driver.core.LocalDate.fromYearMonthDay(
                    localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth());
        } else if (CassandraDataType.BLOB.getTypeName().equals(typeName)
                && paramValue instanceof byte[]) {
            paramValue = ByteBuffer.wrap((byte[]) paramValue);
        }

        parameters.put(paramIndex, paramValue);
    } else {
        super.setParameter(paramIndex, paramValue);
    }
}
 
Example 4
Source File: LocalDateConverter.java    From blog-spring with MIT License 4 votes vote down vote up
@Override
public LocalDate convertToEntityAttribute(Date dbData) {
  return dbData == null ? null : LocalDate.fromDateFields(dbData);
}
 
Example 5
Source File: ValueConverters.java    From morf with Apache License 2.0 4 votes vote down vote up
@Override
public LocalDate localDateValue(java.sql.Date value) {
  return LocalDate.fromDateFields(value);
}
 
Example 6
Source File: GenericJdbcExtractor.java    From sqoop-on-spark with Apache License 2.0 4 votes vote down vote up
@Override
public void extract(ExtractorContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig, GenericJdbcPartition partition) {
  GenericJdbcExecutor executor = new GenericJdbcExecutor(linkConfig.linkConfig);

  String query = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL);
  
  System.out.println("Using query: " + query);

  String conditions = partition.getCondition();
  System.out.println("conditions" + conditions);
  
  query = query.replace(GenericJdbcConnectorConstants.SQL_CONDITIONS_TOKEN, conditions);
  LOG.info("Using query: " + query);

  rowsRead = 0;
  ResultSet resultSet = executor.executeQuery(query);

  Schema schema = context.getSchema();
  Column[] schemaColumns = schema.getColumnsArray();
  try {
    ResultSetMetaData metaData = resultSet.getMetaData();
    int columnCount = metaData.getColumnCount();
    if (schemaColumns.length != columnCount) {
      throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0021, schemaColumns.length + ":" + columnCount);
    }
    while (resultSet.next()) {
      Object[] array = new Object[columnCount];
      for (int i = 0; i < columnCount; i++) {
        if(resultSet.getObject(i + 1) == null) {
          array[i] = null ;
          continue;
        }
        // check type of the column
        Column schemaColumn = schemaColumns[i];
        switch (schemaColumn.getType()) {
        case DATE:
          // convert the sql date to JODA time as prescribed the Sqoop IDF spec
          array[i] = LocalDate.fromDateFields((java.sql.Date)resultSet.getObject(i + 1));
          break;
        case DATE_TIME:
          // convert the sql date time to JODA time as prescribed the Sqoop IDF spec
          array[i] = LocalDateTime.fromDateFields((java.sql.Timestamp)resultSet.getObject(i + 1));
          break;
        case TIME:
          // convert the sql time to JODA time as prescribed the Sqoop IDF spec
          array[i] = LocalTime.fromDateFields((java.sql.Time)resultSet.getObject(i + 1));
          break;
        default:
          //for anything else
          array[i] = resultSet.getObject(i + 1);

        }
      }
      context.getDataWriter().writeArrayRecord(array);
      rowsRead++;
    }
  } catch (SQLException e) {
    throw new SqoopException(
        GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0004, e);

  } finally {
    executor.close();
  }
}
 
Example 7
Source File: DateToJodaLocalDateConverter.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@Override
public LocalDate convert(Date in, Context context) throws Exception {
    if (in == null) return null;
    return LocalDate.fromDateFields(in);
}
 
Example 8
Source File: DateCalculator.java    From AsuraFramework with Apache License 2.0 3 votes vote down vote up
/**
 * 计算日期相隔多少天
 *
 * 计算两个日期之间相隔多少天,忽略时分秒,忽略日期前后顺序
 *  如:2016-09-04 23:59:59 至 2016-09-05 00:00:01 返回相隔1天
 *  跨月如:2016-09-26 23:59:59 至 2016-10-08 00:00:01 返回相隔12天
 * @param date1 日期1
 * @param date2 日期2
 * @return
 */
public static int getBetweenDays(@NotNull Date date1, @NotNull Date date2) {
    Objects.requireNonNull(date1, "date1 must not null");
    Objects.requireNonNull(date2, "date2 must not null");
    LocalDate localDate1 = LocalDate.fromDateFields(date1);
    LocalDate localDate2 = LocalDate.fromDateFields(date2);
    return Math.abs(Days.daysBetween(localDate1, localDate2).getDays());
}
 
Example 9
Source File: ODate.java    From ojai with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an {@code ODate} instance from a {@code java.util.Date} using
 * exactly the same field values. The DATE value is set to the calendar date
 * in the default time zone.
 *
 * @param date  the Date to extract fields from
 */
public ODate(Date date) {
  this(LocalDate.fromDateFields(date));
}