Java Code Examples for org.joda.time.DateTime#getYear()

The following examples show how to use org.joda.time.DateTime#getYear() . 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: YearFunction.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    Expression expression = getChildExpression();
    if (!expression.evaluate(tuple, ptr)) {
        return false;
    }
    if ( ptr.getLength() == 0) {
        return true; //means null
    }
    long dateTime = inputCodec.decodeLong(ptr, expression.getSortOrder());
    DateTime dt = new DateTime(dateTime);
    int year = dt.getYear();
    PDataType returnType = getDataType();
    byte[] byteValue = new byte[returnType.getByteSize()];
    returnType.getCodec().encodeInt(year, byteValue, 0);
    ptr.set(byteValue);
    return true;
}
 
Example 2
Source File: Calendar.java    From CustomizableCalendar with MIT License 6 votes vote down vote up
public Calendar(DateTime firstMonth, DateTime lastMonth) {
    this.firstMonth = firstMonth;
    this.firstDayOfWeek = java.util.Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek();

    DateTime startMonth = firstMonth.plusMonths(1);
    int monthsBetweenCount = Months.monthsBetween(firstMonth, lastMonth).getMonths();

    months = new ArrayList<>();

    months.add(firstMonth);
    currentMonth = firstMonth;

    DateTime monthToAdd = new DateTime(startMonth.getYear(), startMonth.getMonthOfYear(), 1, 0, 0);
    for (int i = 0; i <= monthsBetweenCount; i++) {
        months.add(monthToAdd);
        monthToAdd = monthToAdd.plusMonths(1);
    }
}
 
Example 3
Source File: DateTimeUtil.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the 1st date is before or equal to the 2nd date (comparing only year, month, day).
 *
 * @param date1 1st date object.
 * @param date2 2nd date object.
 * @return true if date1 is before or equal to date2, false if date1 is after date2.
 */
public static boolean isLeftDateBeforeRightDate(DateTime date1, DateTime date2) {
    boolean less = false;
    if (date1.getYear() < date2.getYear()) {
        less = true;
    } else if (date1.getYear() == date2.getYear()) {
        if (date1.getMonthOfYear() < date2.getMonthOfYear()) {
            less = true;
        } else if (date1.getMonthOfYear() == date2.getMonthOfYear()) {
            if (date1.getDayOfMonth() <= date2.getDayOfMonth()) {
                less = true;
            }
        }
    }
    return less;
}
 
Example 4
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public PutTherapeuticLinkResponse mapXMLToPutTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
   PutTherapeuticLinkResponse response = new PutTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalPutTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 5
Source File: IndexerPipelineUtils.java    From dataflow-opinion-analysis with Apache License 2.0 5 votes vote down vote up
public static int getDateIdFromTimestamp(long millis) {
	int result;
	DateTime dt = new DateTime(millis, DateTimeZone.UTC);
	int year = dt.getYear();
	int month = dt.getMonthOfYear();
	int day = dt.getDayOfMonth();
	result = day + (100 * month) + (10000 * year);
	return result;
}
 
Example 6
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public RevokeTherapeuticLinkResponse mapXMLToRevokeTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   RevokeTherapeuticLinkResponse response = new RevokeTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalRevokeTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 7
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public GetTherapeuticLinkResponse mapXMLToGetTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.GetTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   GetTherapeuticLinkResponse response = new GetTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalGetTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapListOfTherapeuticLinks(jaxbResponse.getTherapeuticlinklist()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 8
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public RevokeTherapeuticLinkResponse mapXMLToRevokeTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.RevokeTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   RevokeTherapeuticLinkResponse response = new RevokeTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalRevokeTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 9
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOGetYear() {
    int COUNT = COUNT_VERY_FAST;
    DateTime dt = new DateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "getYear");
        for (int j = 0; j < COUNT; j++) {
            int val = dt.getYear();
            if (val == 0) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 10
Source File: DateTimeUtils.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
public static long roundToMidnight(long timestamp) {
  DateTime dt = new DateTime(timestamp);
  DateTime midnight = new DateTime(dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), 0, 0);
  return midnight.getMillis();
}
 
Example 11
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private TherapeuticLinkRequestType mapOriginalHasTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new HasTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor((AuthorType)request.getAuthor()), (TherapeuticLink)null);
}
 
Example 12
Source File: RecordingList.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * get beginning as date time with time set to 00:00:00:00
 *
 * @return
 */
public DateTime getBeginningAsDate()
{
    DateTime beginning = new DateTime(this.beginning);
    return new DateTime(beginning.getYear(), beginning.getMonthOfYear(), beginning.getDayOfMonth(), 0, 0, 0, 0);
}
 
Example 13
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private TherapeuticLinkRequestType mapOriginalRevokeTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new RevokeTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor(request.getAuthor()), (TherapeuticLink)null, (Proof[])null);
}
 
Example 14
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private TherapeuticLinkRequestType mapOriginalGetTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new GetTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor(request.getAuthor()), (TherapeuticLink)null, 999, (Proof[])null);
}
 
Example 15
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private TherapeuticLinkRequestType mapOriginalRevokeTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new RevokeTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor(request), (TherapeuticLink)null, (Proof[])null);
}
 
Example 16
Source File: ShardingStrategyMonthly.java    From Rhombus with MIT License 4 votes vote down vote up
public long getShardKey(long timestamp){
	DateTime d = new DateTime(timestamp, DateTimeZone.UTC);
	long year = (long)d.getYear();
	long month = (long)d.getMonthOfYear();
	return this.offset + ((year - START_YEAR)*12)+month;
}
 
Example 17
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private DateTime mapDateTime(DateTime date, DateTime time) {
   return new DateTime(date != null ? date.getYear() : 0, date != null ? date.getMonthOfYear() : 1, date != null ? date.getDayOfMonth() : 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
}
 
Example 18
Source File: ResponseObjectMapper.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
private DateTime mapDateTime(DateTime date, DateTime time) {
   return new DateTime(date != null ? date.getYear() : 0, date != null ? date.getMonthOfYear() : 1, date != null ? date.getDayOfMonth() : 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
}
 
Example 19
Source File: DateTimeUtil.java    From cloudhopper-commons with Apache License 2.0 3 votes vote down vote up
/**
 * Null-safe method that returns a new instance of a DateTime object rounded
 * downwards to the nearest second. The time zone of the returned DateTime
 * instance will be the same as the argument. Similar to a floor() function
 * on a float.<br>
 * Examples:
 * <ul>
 *      <li>null -> null
 *      <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:24:51.000 -8:00"
 * </ul>
 * @param value The DateTime value to round downward
 * @return Null if the argument is null or a new instance of the DateTime
 *      value rounded downwards to the nearest second.
 */
public static DateTime floorToSecond(DateTime value) {
    if (value == null) {
        return null;
    }
    return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute(), 0, value.getZone());
}
 
Example 20
Source File: DateUtil.java    From Mycat2 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 获取date对象年份
 * @param date
 * @return
 */
public static int getYear(Date date) {
	DateTime dt = new DateTime(date);
	return dt.getYear();
}