当前位置: 首页>>代码示例>>Java>>正文


Java Datetime类代码示例

本文整理汇总了Java中com.bloomberglp.blpapi.Datetime的典型用法代码示例。如果您正苦于以下问题:Java Datetime类的具体用法?Java Datetime怎么用?Java Datetime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Datetime类属于com.bloomberglp.blpapi包,在下文中一共展示了Datetime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractFieldData

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
/**
 * Extracts time-series.
 */
private void extractFieldData(Element securityElem, String field, Map<String, ExternalIdBundle> reverseBundleMap, Map<ExternalIdBundle, LocalDateDoubleTimeSeriesBuilder> result) {

  String secDes = securityElem.getElementAsString(BloombergConstants.SECURITY);
  ExternalIdBundle identifiers = reverseBundleMap.get(secDes);
  if (identifiers == null) {
    String message = "Found time series data for unrecognized security" + secDes + " " + reverseBundleMap;
    throw new OpenGammaRuntimeException(message);
  }
  LocalDateDoubleTimeSeriesBuilder bld = result.get(identifiers);
  if (bld == null) {
    bld = ImmutableLocalDateDoubleTimeSeries.builder();
    result.put(identifiers, bld);
  }
  Element fieldDataArray = securityElem.getElement(FIELD_DATA);

  int numValues = fieldDataArray.numValues();
  for (int i = 0; i < numValues; i++) {
    Element fieldData = fieldDataArray.getValueAsElement(i);
    Datetime date = fieldData.getElementAsDate("date");
    LocalDate ldate = LocalDate.of(date.year(), date.month(), date.dayOfMonth());
    double lastPrice = fieldData.getElementAsFloat64(field);
    bld.put(ldate, lastPrice);
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:28,代码来源:BloombergHistoricalTimeSeriesProvider.java

示例2: parseBarTickDataArray

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
/**
 * There should be no more error at this point and we can happily parse the interesting portion of the response
 *
 */
private void parseBarTickDataArray(Element barTickDataArray) {
    int countData = barTickDataArray.numValues();
    for (int i = 0; i < countData; i++) {
        Element fieldData = barTickDataArray.getValueAsElement(i);
        Element field = fieldData.getElement(0);
        if (!BarTickDataElements.TIME.asName().equals(field.name())) {
            throw new AssertionError("Time field is supposed to be first but got: " + field.name());
        }
        Datetime dt = field.getValueAsDatetime();

        for (int j = 1; j < fieldData.numElements(); j++) {
            field = fieldData.getElement(j);
            addField(toOffsetDateTime(dt), field);
        }
    }
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:21,代码来源:IntradayBarResultParser.java

示例3: parseTickDataArray

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
/**
 * There should be no more error at this point and we can happily parse the interesting portion of the response
 *
 */
private void parseTickDataArray(Element tickDataArray) {
    int countData = tickDataArray.numValues();
    for (int i = 0; i < countData; i++) {
        Element fieldData = tickDataArray.getValueAsElement(i);
        Element field = fieldData.getElement(0);
        if (!TickDataElements.TIME.asName().equals(field.name())) {
            throw new AssertionError("Time field is supposed to be first but got: " + field.name());
        }
        Datetime dt = field.getValueAsDatetime();
        for (int j = 1; j < fieldData.numElements(); j++) {
            field = fieldData.getElement(j);
            addField(toOffsetDateTime(dt), field);
        }
    }
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:20,代码来源:IntradayTickResultParser.java

示例4: toOffsetTime

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
/**
 * Returns an OffsetDateTime at the same instant with the same offset. If the given Datetime has no time zone information, UTC is assumed (which is supposed
 * to be the default behaviour in Bloomberg.
 *
 * @param dt a Bloomberg Datetime
 *
 * @return an OffsetDateTime Datetime at the same instant with the same offset.
 *
 * @throws NullPointerException if dt is null
 */
public static OffsetTime toOffsetTime(Datetime dt) {
  //not calling toOffsetDateTime here as the date part may not be set or may be set with incorrect values (e.g. month = -1)
  requireNonNull(dt);
  boolean hasTz = dt.hasParts(Datetime.TIME_ZONE_OFFSET);

  int offsetInSeconds = hasTz ? dt.timezoneOffsetMinutes() * 60 : 0;
  ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetInSeconds);

  return OffsetTime.of(dt.hour(), dt.minute(), dt.second(), dt.nanosecond(), offset);
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:21,代码来源:DateUtils.java

示例5: test_invalid_time_issue_18

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
/**
 * From January 16th 2017, the real time field "PROXY_TIME_OF_LAST_UPDATE_RT" has started sending back data with a time datatype but containing dates.
 */
@Test(groups = "unit")
public void test_invalid_time_issue_18() {
  Element mockElement = new MockUp<Element>() {
    @Mock public Schema.Datatype datatype() { return Schema.Datatype.TIME; }
    @Mock public Datetime getValueAsDatetime() { return new Datetime(2017, 1, 1); }
  }.getMockInstance();

  assertEquals(BloombergUtils.getSpecificObjectOf(mockElement), LocalDate.of(2017, 1, 1));
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:13,代码来源:BloombergUtilsTest.java

示例6: toDateTime_ok

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Test public void toDateTime_ok() {
  OffsetDateTime odt = OffsetDateTime.now().plusNanos(7).withOffsetSameInstant(ZoneOffset.ofHoursMinutes(2, 7));
  Datetime dt = DateUtils.toDatetime(odt);

  assertDatesEquals(dt, odt);
  assertEquals(dt.timezoneOffsetMinutes(), 2 * 60 + 7);
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:8,代码来源:DateUtilsTest.java

示例7: toOffsetDateTime_ok

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Test public void toOffsetDateTime_ok() {
  OffsetDateTime expected = OffsetDateTime.now().plusNanos(7).withOffsetSameInstant(ZoneOffset.ofHoursMinutes(2, 7));
  Datetime dt = new Datetime(expected.getYear(), expected.getMonthValue(), expected.getDayOfMonth(), expected.getHour(), expected.getMinute(),
          expected.getSecond(), 0);
  dt.setNanosecond(expected.getNano());
  dt.setTimezoneOffsetMinutes(2 * 60 + 7);

  OffsetDateTime actual = DateUtils.toOffsetDateTime(dt);

  assertEquals(actual, expected);
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:12,代码来源:DateUtilsTest.java

示例8: toOffsetTime_ok

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Test public void toOffsetTime_ok() {
  OffsetTime expected = OffsetTime.now().plusNanos(7).withOffsetSameInstant(ZoneOffset.ofHoursMinutes(2, 7));
  Datetime dt = new Datetime(expected.getHour(), expected.getMinute(), expected.getSecond(), 0);
  dt.setNanosecond(expected.getNano());
  dt.setTimezoneOffsetMinutes(2 * 60 + 7);

  OffsetTime actual = DateUtils.toOffsetTime(dt);

  assertEquals(actual, expected);
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:11,代码来源:DateUtilsTest.java

示例9: toLocalDate_ok

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Test public void toLocalDate_ok() {
  LocalDate expected = LocalDate.of(2015, 1, 1);
  Datetime dt = new Datetime(2015, 1, 1);

  LocalDate actual = DateUtils.toLocalDate(dt);

  assertEquals(actual, expected);
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:9,代码来源:DateUtilsTest.java

示例10: assertDatesEquals

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
private void assertDatesEquals(Datetime dt, OffsetDateTime odt) {
  assertEquals(dt.year(), odt.getYear());
  assertEquals(dt.month(), odt.getMonth().getValue());
  assertEquals(dt.dayOfMonth(), odt.getDayOfMonth());
  assertEquals(dt.hour(), odt.getHour());
  assertEquals(dt.minute(), odt.getMinute());
  assertEquals(dt.second(), odt.getSecond());
  assertEquals(dt.nanosecond(), odt.getNano());
  assertEquals(dt.timezoneOffsetMinutes(), odt.getOffset().getTotalSeconds() / 60);
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:11,代码来源:DateUtilsTest.java

示例11: getSpecificObjectOf

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
/**
 * Transforms a Bloomberg Element into the most specific Object (for example: Double, Float, Integer, DateTime,
 * String etc.).<br>
 * Complex types are returned in the form of collections ({@code List<Object>} for arrays and
 * {@code Map<String, Object>}
 * for sequences).
 */
public static Object getSpecificObjectOf(Element field) {
    if (field.datatype() == Schema.Datatype.FLOAT64) {
        //likeliest data type
        return field.getValueAsFloat64();
    } else if (field.datatype() == Schema.Datatype.FLOAT32) {
        return field.getValueAsFloat32();
    } else if (field.datatype() == Schema.Datatype.BOOL) {
        return field.getValueAsBool();
    } else if (field.datatype() == Schema.Datatype.CHAR) {
        return field.getValueAsChar();
    } else if (field.datatype() == Schema.Datatype.INT32) {
        return field.getValueAsInt32();
    } else if (field.datatype() == Schema.Datatype.INT64) {
        return field.getValueAsInt64();
    } else if (field.datatype() == Schema.Datatype.STRING) {
        return field.getValueAsString();
    } else if (field.datatype() == Schema.Datatype.DATE
            || field.datatype() == Schema.Datatype.TIME
            || field.datatype() == Schema.Datatype.DATETIME) {
      Datetime dt = field.getValueAsDatetime();
      if (dt.hasParts(Datetime.DATE)) {
        return dt.hasParts(Datetime.TIME) ? toOffsetDateTime(dt)
                                          : toLocalDate(dt);
      } else {
        if (dt.hasParts(Datetime.TIME)) return toOffsetTime(dt);
        logger.warn("Not a valid date time: Element={}, Datetime={}", field, dt);
        return null;
      }
    } else if (field.isArray()) {
        List<Object> list = new ArrayList<>(field.numValues());
        for (int i = 0; i < field.numValues(); i++) {
            list.add(getSpecificObjectOf(field.getValueAsElement(i)));
        }
        return list;
    } else if (field.datatype() == Schema.Datatype.SEQUENCE
            || field.datatype() == Schema.Datatype.CHOICE) { //has to be after array because arrays are sequences...
        ElementIterator it = field.elementIterator();
        Map<String, Object> map = new LinkedHashMap<>(field.numElements(), 1.0f);
        while (it.hasNext()) {
            Element e = it.next();
            map.put(e.name().toString(), getSpecificObjectOf(e));
        }
        return map;
    } else {
        return field.toString(); //always works
    }
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:55,代码来源:BloombergUtils.java

示例12: getElementAsDatetime

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Override
public Datetime getElementAsDatetime(Name name) {
  throw new UnsupportedOperationException("Not supported yet.");
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:5,代码来源:MockMessage.java

示例13: getElementAsDate

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Override
public Datetime getElementAsDate(Name name) {
  throw new UnsupportedOperationException("Not supported yet.");
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:5,代码来源:MockMessage.java

示例14: getElementAsTime

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Override
public Datetime getElementAsTime(Name name) {
  throw new UnsupportedOperationException("Not supported yet.");
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:5,代码来源:MockMessage.java

示例15: toOffsetDateTime_no_tz

import com.bloomberglp.blpapi.Datetime; //导入依赖的package包/类
@Test public void toOffsetDateTime_no_tz() {
  OffsetDateTime expected = OffsetDateTime.of(2015, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC);
  OffsetDateTime actual = DateUtils.toOffsetDateTime(new Datetime(2015, 1, 1, 12, 0, 0, 0));

  assertEquals(actual, expected);
}
 
开发者ID:assylias,项目名称:jBloomberg,代码行数:7,代码来源:DateUtilsTest.java


注:本文中的com.bloomberglp.blpapi.Datetime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。