Tabnine Logo
BaseDateTimeDt
Code IndexAdd Tabnine to your IDE (free)

How to use
BaseDateTimeDt
in
ca.uhn.fhir.model.primitive

Best Java code snippets using ca.uhn.fhir.model.primitive.BaseDateTimeDt (Showing top 20 results out of 315)

origin: jamesagnew/hapi-fhir

/**
 * Returns the value of this object as a {@link GregorianCalendar}
 */
public GregorianCalendar getValueAsCalendar() {
  if (getValue() == null) {
    return null;
  }
  GregorianCalendar cal;
  if (getTimeZone() != null) {
    cal = new GregorianCalendar(getTimeZone());
  } else {
    cal = new GregorianCalendar();
  }
  cal.setTime(getValue());
  return cal;
}
origin: jamesagnew/hapi-fhir

private BaseDateTimeDt setTimeZone(String theWholeValue, String theValue) {
  if (isBlank(theValue)) {
    throwBadDateFormat(theWholeValue);
  } else if (theValue.charAt(0) == 'Z') {
    clearTimeZone();
    setTimeZoneZulu(true);
  } else if (theValue.length() != 6) {
    throwBadDateFormat(theWholeValue, "Timezone offset must be in the form \"Z\", \"-HH:mm\", or \"+HH:mm\"");
  } else if (theValue.charAt(3) != ':' || !(theValue.charAt(0) == '+' || theValue.charAt(0) == '-')) {
    throwBadDateFormat(theWholeValue, "Timezone offset must be in the form \"Z\", \"-HH:mm\", or \"+HH:mm\"");
  } else {
    parseInt(theWholeValue, theValue.substring(1, 3), 0, 23);
    parseInt(theWholeValue, theValue.substring(4, 6), 0, 59);
    clearTimeZone();
    setTimeZone(TimeZone.getTimeZone("GMT" + theValue));
  }
  return this;
}
origin: jamesagnew/hapi-fhir

/**
 * Gets the precision for this datatype (using the default for the given type if not set)
 * 
 * @see #setPrecision(TemporalPrecisionEnum)
 */
public TemporalPrecisionEnum getPrecision() {
  if (myPrecision == null) {
    return getDefaultPrecisionForDatatype();
  }
  return myPrecision;
}
origin: jamesagnew/hapi-fhir

/**
 * Constructor
 * 
 * @throws DataFormatException
 *            If the specified precision is not allowed for this type
 */
public BaseDateTimeDt(String theString) {
  setValueAsString(theString);
  validatePrecisionAndThrowDataFormatException(theString, getPrecision());
}
origin: jamesagnew/hapi-fhir

/**
 * Sets the value for this type using the given Java Date object as the time, and using the default precision for
 * this datatype (unless the precision is already set), as well as the local timezone as determined by the local operating
 * system. Both of these properties may be modified in subsequent calls if neccesary.
 */
@Override
public BaseDateTimeDt setValue(Date theValue) {
  setValue(theValue, getPrecision());
  return this;
}
origin: jamesagnew/hapi-fhir

private Integer getFieldValue(int theField) {
  if (getValue() == null) {
    return null;
  }
  Calendar cal = getValueAsCalendar();
  return cal.get(theField);
}
origin: jamesagnew/hapi-fhir

  throwBadDateFormat(value);
cal.set(Calendar.YEAR, parseInt(value, value.substring(0, 4), 0, 9999));
precision = TemporalPrecisionEnum.YEAR;
if (length > 4) {
  validateCharAtIndexIs(value, 4, '-');
  validateLengthIsAtLeast(value, 7);
  int monthVal = parseInt(value, value.substring(5, 7), 1, 12) - 1;
  cal.set(Calendar.MONTH, monthVal);
  precision = TemporalPrecisionEnum.MONTH;
  if (length > 7) {
    validateCharAtIndexIs(value, 7, '-');
    validateLengthIsAtLeast(value, 10);
    cal.set(Calendar.DATE, 1); // for some reason getActualMaximum works incorrectly if date isn't set
    int actualMaximum = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum));
    precision = TemporalPrecisionEnum.DAY;
    if (length > 10) {
      validateLengthIsAtLeast(value, 16);
      validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss
      int offsetIdx = getOffsetIndex(value);
      String time;
      if (offsetIdx == -1) {
        time = value.substring(11, offsetIdx);
        String offsetString = value.substring(offsetIdx);
        setTimeZone(value, offsetString);
        cal.setTimeZone(getTimeZone());
origin: jamesagnew/hapi-fhir

private void setFieldValue(int theField, int theValue, String theFractionalSeconds, int theMinimum, int theMaximum) {
  validateValueInRange(theValue, theMinimum, theMaximum);
  Calendar cal;
  if (getValue() == null) {
    cal = new GregorianCalendar(0, 0, 0);
  } else {
    cal = getValueAsCalendar();
  }
  if (theField != -1) {
    cal.set(theField, theValue);
  }
  if (theFractionalSeconds != null) {
    myFractionalSeconds = theFractionalSeconds;
  } else if (theField == Calendar.MILLISECOND) {
    myFractionalSeconds = StringUtils.leftPad(Integer.toString(theValue), 3, '0');
  }
  super.setValue(cal.getTime());
}
origin: jamesagnew/hapi-fhir

/**
 * Returns a human readable version of this date/time using the system local format.
 * <p>
 * <b>Note on time zones:</b> This method renders the value using the time zone that is contained within the value.
 * For example, if this date object contains the value "2012-01-05T12:00:00-08:00",
 * the human display will be rendered as "12:00:00" even if the application is being executed on a system in a
 * different time zone. If this behaviour is not what you want, use
 * {@link #toHumanDisplayLocalTimezone()} instead.
 * </p>
 */
public String toHumanDisplay() {
  TimeZone tz = getTimeZone();
  Calendar value = tz != null ? Calendar.getInstance(tz) : Calendar.getInstance();
  value.setTime(getValue());
  switch (getPrecision()) {
  case YEAR:
  case MONTH:
  case DAY:
    return ourHumanDateFormat.format(value);
  case MILLI:
  case SECOND:
  default:
    return ourHumanDateTimeFormat.format(value);
  }
}
origin: jamesagnew/hapi-fhir

if (nextObject instanceof BaseDateTimeDt) {
  BaseDateTimeDt nextValue = (BaseDateTimeDt) nextObject;
  if (nextValue.isEmpty()) {
    continue;
  nextEntity = new ResourceIndexedSearchParamDate(nextSpDef.getName(), nextValue.getValue(), nextValue.getValue(), nextValue.getValueAsString());
} else if (nextObject instanceof PeriodDt) {
  PeriodDt nextValue = (PeriodDt) nextObject;
origin: jamesagnew/hapi-fhir

/**
 * Returns a human readable version of this date/time using the system local format, converted to the local timezone
 * if neccesary.
 * 
 * @see #toHumanDisplay() for a method which does not convert the time to the local timezone before rendering it.
 */
public String toHumanDisplayLocalTimezone() {
  switch (getPrecision()) {
  case YEAR:
  case MONTH:
  case DAY:
    return ourHumanDateFormat.format(getValue());
  case MILLI:
  case SECOND:
  default:
    return ourHumanDateTimeFormat.format(getValue());
  }
}
origin: jamesagnew/hapi-fhir

/**
 * Returns the month with 1-index, e.g. 1=the first day of the month
 */
public Integer getDay() {
  return getFieldValue(Calendar.DAY_OF_MONTH);
}
origin: jamesagnew/hapi-fhir

/**
 * Returns <code>true</code> if this object represents a date that is today's date
 * 
 * @throws NullPointerException
 *            if {@link #getValue()} returns <code>null</code>
 */
public boolean isToday() {
  Validate.notNull(getValue(), getClass().getSimpleName() + " contains null value");
  return DateUtils.isSameDay(new Date(), getValue());
}
origin: jamesagnew/hapi-fhir

/**
 * Sets the value for this type using the given Java Date object as the time, and using the specified precision, as
 * well as the local timezone as determined by the local operating system. Both of
 * these properties may be modified in subsequent calls if neccesary.
 * 
 * @param theValue
 *           The date value
 * @param thePrecision
 *           The precision
 * @throws DataFormatException
 */
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException {
  if (getTimeZone() == null) {
    setTimeZone(TimeZone.getDefault());
  }
  myPrecision = thePrecision;
  myFractionalSeconds = "";
  if (theValue != null) {
    long millis = theValue.getTime() % 1000;
    if (millis < 0) {
      // This is for times before 1970 (see bug #444)
      millis = 1000 + millis;
    }
    String fractionalSeconds = Integer.toString((int) millis);
    myFractionalSeconds = StringUtils.leftPad(fractionalSeconds, 3, '0');
  }
  super.setValue(theValue);
}
origin: jamesagnew/hapi-fhir

@Override
public void setValueAsString(String theValue) throws DataFormatException {
  clearTimeZone();
  super.setValueAsString(theValue);
}
origin: ca.uhn.hapi.fhir/hapi-fhir-base

  throwBadDateFormat(value);
cal.set(Calendar.YEAR, parseInt(value, value.substring(0, 4), 0, 9999));
precision = TemporalPrecisionEnum.YEAR;
if (length > 4) {
  validateCharAtIndexIs(value, 4, '-');
  validateLengthIsAtLeast(value, 7);
  int monthVal = parseInt(value, value.substring(5, 7), 1, 12) - 1;
  cal.set(Calendar.MONTH, monthVal);
  precision = TemporalPrecisionEnum.MONTH;
  if (length > 7) {
    validateCharAtIndexIs(value, 7, '-');
    validateLengthIsAtLeast(value, 10);
    cal.set(Calendar.DATE, 1); // for some reason getActualMaximum works incorrectly if date isn't set
    int actualMaximum = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.DAY_OF_MONTH, parseInt(value, value.substring(8, 10), 1, actualMaximum));
    precision = TemporalPrecisionEnum.DAY;
    if (length > 10) {
      validateLengthIsAtLeast(value, 16);
      validateCharAtIndexIs(value, 10, 'T'); // yyyy-mm-ddThh:mm:ss
      int offsetIdx = getOffsetIndex(value);
      String time;
      if (offsetIdx == -1) {
        time = value.substring(11, offsetIdx);
        String offsetString = value.substring(offsetIdx);
        setTimeZone(value, offsetString);
        cal.setTimeZone(getTimeZone());
origin: ca.uhn.hapi.fhir/hapi-fhir-base

private void setFieldValue(int theField, int theValue, String theFractionalSeconds, int theMinimum, int theMaximum) {
  validateValueInRange(theValue, theMinimum, theMaximum);
  Calendar cal;
  if (getValue() == null) {
    cal = new GregorianCalendar(0, 0, 0);
  } else {
    cal = getValueAsCalendar();
  }
  if (theField != -1) {
    cal.set(theField, theValue);
  }
  if (theFractionalSeconds != null) {
    myFractionalSeconds = theFractionalSeconds;
  } else if (theField == Calendar.MILLISECOND) {
    myFractionalSeconds = StringUtils.leftPad(Integer.toString(theValue), 3, '0');
  }
  super.setValue(cal.getTime());
}
origin: ca.uhn.hapi.fhir/hapi-fhir-base

/**
 * Returns a human readable version of this date/time using the system local format.
 * <p>
 * <b>Note on time zones:</b> This method renders the value using the time zone that is contained within the value.
 * For example, if this date object contains the value "2012-01-05T12:00:00-08:00",
 * the human display will be rendered as "12:00:00" even if the application is being executed on a system in a
 * different time zone. If this behaviour is not what you want, use
 * {@link #toHumanDisplayLocalTimezone()} instead.
 * </p>
 */
public String toHumanDisplay() {
  TimeZone tz = getTimeZone();
  Calendar value = tz != null ? Calendar.getInstance(tz) : Calendar.getInstance();
  value.setTime(getValue());
  switch (getPrecision()) {
  case YEAR:
  case MONTH:
  case DAY:
    return ourHumanDateFormat.format(value);
  case MILLI:
  case SECOND:
  default:
    return ourHumanDateTimeFormat.format(value);
  }
}
origin: ca.uhn.hapi.fhir/hapi-fhir-base

/**
 * Constructor
 * 
 * @throws DataFormatException
 *            If the specified precision is not allowed for this type
 */
public BaseDateTimeDt(String theString) {
  setValueAsString(theString);
  validatePrecisionAndThrowDataFormatException(theString, getPrecision());
}
origin: ca.uhn.hapi.fhir/hapi-fhir-base

private Integer getFieldValue(int theField) {
  if (getValue() == null) {
    return null;
  }
  Calendar cal = getValueAsCalendar();
  return cal.get(theField);
}
ca.uhn.fhir.model.primitiveBaseDateTimeDt

Most used methods

  • getValue
  • clearTimeZone
  • getDefaultPrecisionForDatatype
    Returns the default precision for the given datatype
  • getFieldValue
  • getOffsetIndex
  • getPrecision
    Gets the precision for this datatype (using the default for the given type if not set)
  • getTimeZone
    Returns the TimeZone associated with this dateTime's value. May return null if no timezone was suppl
  • getValueAsCalendar
    Returns the value of this object as a GregorianCalendar
  • getValueAsString
  • isEmpty
  • isPrecisionAllowed
    To be implemented by subclasses to indicate whether the given precision is allowed by this type
  • leftPadWithZeros
  • isPrecisionAllowed,
  • leftPadWithZeros,
  • parseInt,
  • setFieldValue,
  • setPrecision,
  • setTimeZone,
  • setTimeZoneZulu,
  • setValue,
  • setValueAsString,
  • throwBadDateFormat

Popular in Java

  • Start an intent from android
  • getResourceAsStream (ClassLoader)
  • addToBackStack (FragmentTransaction)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JButton (javax.swing)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now