Java Code Examples for java.time.LocalDateTime#plus()

The following examples show how to use java.time.LocalDateTime#plus() . 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: AppointmentTest.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void setStateIncludesStateHistory() {
	LocalDateTime begin = LocalDateTime.of(2018, 9, 24, 13, 23);
	LocalDateTime end = begin.plus(Duration.ofMinutes(15));
	
	IAppointment appointment = coreModelService.create(IAppointment.class);
	appointment.setReason("reason");
	appointment.setStartTime(begin);
	appointment.setEndTime(end);
	appointment.setState("started");
	coreModelService.save(appointment);
	
	assertTrue(appointment.getStateHistory().contains("started"));
	
	appointment.setState("modified");
	coreModelService.save(appointment);
	
	assertTrue(appointment.getStateHistory().contains("started"));
	assertTrue(appointment.getStateHistory().contains("modified"));
		
	coreModelService.remove(appointment);
}
 
Example 2
Source File: TimerChecker.java    From FX-AlgorithmTrading with MIT License 6 votes vote down vote up
/**
 * すべてのスケールの基準時刻を指定時間まで進めます
 * @param nextBaseTime
 */
private void putForwardTimeToNext(LocalDateTime nextBaseTime) {

    for (Period period : TIMER_PERIODS) {
        LocalDateTime lastDateTime = lastDateTimeMap.get(period);
        LocalDateTime nextDateTime = nextDateTimeMap.get(period);

        // 指定時刻まで進める
        while (nextDateTime.isBefore(nextBaseTime)) {
            lastDateTime = nextDateTime;
            nextDateTime = nextDateTime.plus(period.getTimeInverval(), period.getChronoUnit());
        }

        // LocalDateTime は immutable なので入れなおす
        lastDateTimeMap.put(period, lastDateTime);
        nextDateTimeMap.put(period, nextDateTime);
    }
}
 
Example 3
Source File: IntervalShardingAlgorithm.java    From shardingsphere with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<String> doSharding(final Collection<String> availableTargetNames, final RangeShardingValue<Comparable<?>> shardingValue) {
    boolean hasStartTime = shardingValue.getValueRange().hasLowerBound();
    boolean hasEndTime = shardingValue.getValueRange().hasUpperBound();
    if (!hasStartTime && !hasEndTime) {
        return availableTargetNames;
    }
    LocalDateTime startTime = hasStartTime ? parseDateTime(shardingValue.getValueRange().lowerEndpoint().toString()) : dateTimeLower;
    LocalDateTime endTime = hasEndTime ? parseDateTime(shardingValue.getValueRange().upperEndpoint().toString()) : dateTimeUpper;
    LocalDateTime calculateTime = startTime;
    Set<String> result = new HashSet<>();
    while (!calculateTime.isAfter(endTime)) {
        result.addAll(getMatchedTables(calculateTime, availableTargetNames));
        calculateTime = calculateTime.plus(stepAmount, stepUnit);
    }
    result.addAll(getMatchedTables(endTime, availableTargetNames));
    return result;
}
 
Example 4
Source File: RangeBasicTests.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "localDateTimeRanges")
public void testRangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, boolean parallel) {
    final Range<LocalDateTime> range = Range.of(start, end, step);
    final Array<LocalDateTime> array = range.toArray(parallel);
    final boolean ascend = start.isBefore(end);
    final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.SECONDS.between(start, end)) / (double)step.getSeconds());
    Assert.assertEquals(array.length(), expectedLength);
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATETIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    LocalDateTime expected = null;
    for (int i=0; i<array.length(); ++i) {
        final LocalDateTime actual = array.getValue(i);
        expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
        Assert.assertEquals(actual, expected, "Value matches at " + i);
        Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
    }
}
 
Example 5
Source File: RangeFilterTests.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "LocalDateTimeRanges")
public void testRangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, boolean parallel) {
    final boolean ascend = start.isBefore(end);
    final Range<LocalDateTime> range = Range.of(start, end, step, v -> v.getHour() == 6);
    final Array<LocalDateTime> array = range.toArray(parallel);
    final LocalDateTime first = array.first(v -> true).map(ArrayValue::getValue).get();
    final LocalDateTime last = array.last(v -> true).map(ArrayValue::getValue).get();
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATETIME);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    int index = 0;
    LocalDateTime value = first;
    while (ascend ? value.isBefore(last) : value.isAfter(last)) {
        final LocalDateTime actual = array.getValue(index);
        Assert.assertEquals(actual, value, "Value matches at " + index);
        Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
        value = ascend ? value.plus(step) : value.minus(step);
        while (value.getHour() == 6) value = ascend ? value.plus(step) : value.minus(step);
        index++;
    }
}
 
Example 6
Source File: PeriodTrigger.java    From geoportal-server-harvester with Apache License 2.0 6 votes vote down vote up
private synchronized void schedule(Date lastHarvest, Runnable runnable) {
  try {
    if (lastHarvest==null) {
      LOG.info(String.format("Task is being submitted now: %s", triggerDefinition.getTaskDefinition()));
      future = service.submit(runnable);
    } else {
      TemporalAmount tempAmt = parseTemporalAmount(triggerDefinition.getProperties().get(T_PERIOD));
      LocalDateTime lh = LocalDateTime.ofInstant(lastHarvest.toInstant(), ZoneId.systemDefault() );
      LocalDateTime nh = lh.plus(tempAmt);
      long delay = (nh.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() - lh.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli())/1000/60;
      
      if (delay>0) {
        LOG.info(String.format("Task is scheduled to be run in %d minutes: %s", delay, triggerDefinition.getTaskDefinition()));
        future = service.schedule(runnable, delay, TimeUnit.MINUTES);
      } else {
        LOG.info(String.format("Task is being submitted now: %s", triggerDefinition.getTaskDefinition()));
        future = service.submit(runnable);
      }
    }
  } catch (ParseException ex) {
    LOG.error(String.format("Error activating trigger: %s", getType()), ex);
  }
}
 
Example 7
Source File: BinlogDateConvert.java    From kafka-connectors with Apache License 2.0 5 votes vote down vote up
public static String dateConvert(String schemaName, String value) {
    if (TIMESTAMP_CLASS.equalsIgnoreCase(schemaName)) {
        LocalDateTime dateTime;
        try {
            dateTime = LocalDateTime.parse(value, UTC_DATE_TIME_DF);
        } catch (DateTimeParseException e) {
            dateTime = LocalDateTime.parse(value, UTC_Z_DATE_TIME_DF);
        }
        dateTime = dateTime.plus(8L, ChronoUnit.HOURS);
        return DATE_TIME_DF.format(dateTime);
    } else {
        return value;
    }
}
 
Example 8
Source File: WindowFunction.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object apply(LocalDateTime value) {
    LocalDateTime ndt = LocalDateTime.now();
    ChronoUnit cu = JDateUtil.getChronoUnit(this.period);
    switch (cu) {
        case SECONDS:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(),
                    value.getHour(), value.getMinute(), 0);
            break;
        case MINUTES:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(),
                    value.getHour(), 0, 0);
            break;
        case HOURS:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), value.getDayOfMonth(),
                    0, 0, 0);
            break;
        case DAYS:
            ndt = LocalDateTime.of(value.getYear(), value.getMonthValue(), 1,
                    0, 0, 0);
            break;
        case MONTHS:
            ndt = LocalDateTime.of(value.getYear(), 1, 1, 0, 0, 0);
            break;
        case YEARS:
            int n = ((Period)period).getYears();
            ndt = LocalDateTime.of(value.getYear() - n, 1, 1, 0, 0, 0);
    }
    
    while (ndt.isBefore(value)){
        ndt = ndt.plus(period);
    }
    if (ndt.isAfter(value))
        ndt = ndt.minus(period);
    
    return ndt;
}
 
Example 9
Source File: TestSolution3PeriodsAndDurations.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(2)
public void verifyPeriodCreatedUsingFluentMethods() {

    // Create a Period instance
    // TODO: Replace the Period.ZERO to a time period of 20 years and 10 days.
    //  Check : java.time.Period.ofYears(int).withDays(int)
    Period twentyYearsAndTenDays = Period.ofYears(20).withDays(10);

    assertEquals(20,
            twentyYearsAndTenDays.get(ChronoUnit.YEARS),
            "The Period should include twenty years");

    assertEquals(10,
            twentyYearsAndTenDays.get(ChronoUnit.DAYS),
            "The Period should include ten days");


    // Add the Period to a LocalDateTime
    LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);

    // TODO: Call a method on tOJDateTime to add the newly created Period
    //  Check : java.time.LocalDateTime.plus(java.time.temporal.TemporalAmount)
    LocalDateTime calculatedTwentyYearsAndTenDaysLater =
            tOJDateTime.plus(twentyYearsAndTenDays);

    //1997-08-29 after 20 years and 10 days => 2017-09=08
    assertEquals(2017,
            calculatedTwentyYearsAndTenDaysLater.getYear(),
            "The year after 20 years and 10 days should be 2017");

    assertEquals(9,
            calculatedTwentyYearsAndTenDaysLater.getMonthValue(),
            "The month value after 20 years and 10 days should be 9");

    assertEquals(8,
            calculatedTwentyYearsAndTenDaysLater.getDayOfMonth(),
            "The date after 20 years and 10 days should be 8");
}
 
Example 10
Source File: TestSolution3PeriodsAndDurations.java    From java-katas with MIT License 5 votes vote down vote up
@Test
@Tag("PASSING")
@Order(3)
public void verifyDurationCreatedUsingIntegersAndChronoUnits() {

    // Create a Duration instance
    // TODO: Replace the Duration.ZERO to a duration of 3 hours and 6 seconds.
    //  Check: java.time.Duration.of(int, ChronoUnit)
    Duration threeHoursAndSixSeconds = Duration.of(10806, ChronoUnit.SECONDS);

    assertEquals(3,
            threeHoursAndSixSeconds.toHours(),
            "The time duration should include three hours.");

    assertEquals(10806,
            threeHoursAndSixSeconds.getSeconds(),
            "The time duration should include three hours and six seconds in seconds.");


    // Add the Duration to a LocalDateTime
    LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);

    // TODO: Call a method on tOJDateTime to add the newly created Duration
    //  Check : java.time.LocalDateTime.plus(java.time.temporal.TemporalAmount)
    LocalDateTime calculatedThreeHoursAndSixSecondsLater =
            tOJDateTime.plus(threeHoursAndSixSeconds);

    //7:14:30 GMT = 2:14:30 in (GMT-5). Adding 3h 6s = 5:14:36 in (GMT-5)
    assertEquals(5,
            calculatedThreeHoursAndSixSecondsLater.getHour(),
            "The hour after 3 hours and six seconds should be 5.");

    assertEquals(14,
            calculatedThreeHoursAndSixSecondsLater.getMinute(),
            "The minute after 3 hours and six seconds should be 14.");

    assertEquals(36,
            calculatedThreeHoursAndSixSecondsLater.getSecond(),
            "The second after 3 hours and six seconds should be 36.");
}
 
Example 11
Source File: DateUtil.java    From java-trader with Apache License 2.0 5 votes vote down vote up
/**
 * 规整时间的秒
 */
public static LocalDateTime round(LocalDateTime ldt) {
    int seconds = ldt.get(ChronoField.SECOND_OF_MINUTE);
    if (seconds >= 59) {
        ldt = ldt.plus(1, ChronoUnit.SECONDS);
    }
    return ldt.truncatedTo(ChronoUnit.SECONDS);
}
 
Example 12
Source File: Appointment.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public LocalDateTime getEndTime(){
	LocalDateTime start = getStartTime();
	if(start != null) {
		Integer duration = getDurationMinutes();
		if(duration != null) {
			return start.plus(Duration.ofMinutes(duration));
		}
	}
	return null;
}
 
Example 13
Source File: ProductionOutputEntity.java    From factory with MIT License 5 votes vote down vote up
ProductionOutputEntity(String refNo,
                       LocalDateTime start, Duration duration,
                       int partsPerMinute,
                       long total) {
    this.refNo = refNo;
    this.start = start;
    this.duration = duration.getSeconds();
    this.end = start.plus(duration);
    this.partsPerMinute = partsPerMinute;
    this.total = total;
}
 
Example 14
Source File: ModifyStepDefinitions.java    From IridiumApplicationTesting with MIT License 5 votes vote down vote up
/**
 * Save the current date and time to an aliased value.
 * @param format The format of the date: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
 * @param offsetAlias include the word alias to get the value of the offset from an aliased value
 * @param offsetAmount The optional amount to offset todays date by e.g. "1 day" or "2 weeks"
 * @param alias The alias to save the date into
 */
@When("^I save the current date(?: offset by( alias)? \"(.*?)\")? with the format \"(.*?)\" to(?: the)? alias \"(.*?)\"")
public void saveDateToAlias(
	final String offsetAlias,
	final String offsetAmount,
	final String format,
	final String alias) {

	final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(format);
	final Map<String, String> dataset = State.getFeatureStateForThread().getDataSet();

	LocalDateTime date = LocalDateTime.now();

	if (StringUtils.isNotBlank(offsetAmount)) {
		final String fixedOffsetAmount = autoAliasUtils.getValue(
			offsetAmount,
			StringUtils.isNotBlank(offsetAlias),
			State.getFeatureStateForThread());

		if (!fixedOffsetAmount.matches("^-?\\d+ \\w+$")) {
			throw new InvalidInputException(
				fixedOffsetAmount + " needs to match the format \"^-?\\d+ \\w+$\"");
		}

		final String[] offsetRaw = fixedOffsetAmount.split(" ");
		final int offset = Integer.parseInt(offsetRaw[0]);
		final ChronoUnit chronoUnit = chronoConverterUtils.fromString(offsetRaw[1]);
		date = date.plus(offset, chronoUnit);
	}

	dataset.put(alias, dateFormatter.format(date));
	State.getFeatureStateForThread().setDataSet(dataset);
}
 
Example 15
Source File: TimerChecker.java    From FX-AlgorithmTrading with MIT License 4 votes vote down vote up
/**
 * TImerの更新をチェックします。
 *
 * @param updateDateTime
 */
public synchronized void checkTime(LocalDateTime updateDateTime) {
    LocalDateTime nextDateTime1min = nextDateTimeMap.get(SHORTEST_PERIOD);

    // 最小更新間隔である1分の更新をチェックして、更新がなければ全部更新しない
    if (updateDateTime.isBefore(nextDateTime1min)) {
        return;
    }

    // Market Close 時間帯は更新しない
    if (!MarketTimeUtility.isMarketOpened(nextDateTime1min)) {
        // 次のOpen時刻まで進める
        putForwardTimeToNext(MarketTimeUtility.getNextOpenTime(nextDateTime1min));
        return;
    }

    // 土曜日は Market Close 15分前に WEEK_ENDイベントを送信する
    if (!onWeekend && updateDateTime.getDayOfWeek() == DayOfWeek.SATURDAY) {
        LocalTime closeTime = MarketTimeUtility.getCloseWeekTimeSaturday(updateDateTime.toLocalDate());
        if(!updateDateTime.toLocalTime().isBefore(closeTime.minusMinutes(WEEKEND_BEFORE_MINUTES))) {
            onWeekend = true;
            eventGenarator.sendWeekEndEvent(nextDateTime1min);
        }
    } else if (onWeekend && updateDateTime.getDayOfWeek() == DayOfWeek.MONDAY) {
        // 月曜はStart時刻に開始イベントを送信する
        LocalTime openTime = MarketTimeUtility.getOpenWeekTimeMonday(updateDateTime.toLocalDate());
        if(!updateDateTime.toLocalTime().isBefore(openTime)) {
            onWeekend = false;
            eventGenarator.sendWeekStartEvent(nextDateTime1min);
        }
    }

    // 各基準時刻を進める
    for (Period period : TIMER_PERIODS) {
        LocalDateTime lastDateTime = lastDateTimeMap.get(period);
        LocalDateTime nextDateTime = nextDateTimeMap.get(period);
        // 5min以降の比較用
        LocalDateTime lastDateTime1min = lastDateTimeMap.get(SHORTEST_PERIOD);

        // 現在時刻が次の更新予定時刻以降
        if (!updateDateTime.isBefore(nextDateTime)) {
            // その時刻のMIN_1が更新されていなければ抜ける(先にMIN_1を更新する)
            if (period != SHORTEST_PERIOD && lastDateTime1min.isBefore(nextDateTime)) {
                return;
            }

            // 更新時刻、次回時刻を設定
            lastDateTime = nextDateTime;
            if (period != Period.DAILY) {
                nextDateTime = nextDateTime.plus(period.getTimeInverval(), period.getChronoUnit());
            } else {
                nextDateTime = culcurateNextDailyUpdate(nextDateTime.toLocalDate());
            }
            sendTimerEvent(period, lastDateTime, nextDateTime);

            // LocalDateTime は immutable なので入れなおす
            lastDateTimeMap.put(period, lastDateTime);
            nextDateTimeMap.put(period, nextDateTime);
        } else {
            // 更新が無い場合、より長い時刻は更新しない
            return;
        }
    }
}
 
Example 16
Source File: LocalDateTimeUtils.java    From admin-plus with Apache License 2.0 4 votes vote down vote up
public static LocalDateTime plus(LocalDateTime time, long number, TemporalUnit field) {
    return time.plus(number, field);
}
 
Example 17
Source File: Axis.java    From charts with Apache License 2.0 4 votes vote down vote up
private List<LocalDateTime> createTickValues(final double WIDTH, final LocalDateTime START, final LocalDateTime END) {
    List<LocalDateTime> dateList = new ArrayList<>();
    LocalDateTime       dateTime = LocalDateTime.now();

    if (null == START || null == END) return dateList;

    // The preferred gap which should be between two tick marks.
    double majorTickSpace = 100;
    double noOfTicks      = WIDTH / majorTickSpace;

    List<LocalDateTime> previousDateList = new ArrayList<>();
    Interval            previousInterval = Interval.values()[0];

    // Starting with the greatest interval, add one of each dateTime unit.
    for (Interval interval : Interval.values()) {
        // Reset the dateTime.
        dateTime = LocalDateTime.of(START.toLocalDate(), START.toLocalTime());
        // Clear the list.
        dateList.clear();
        previousDateList.clear();
        currentInterval = interval;

        // Loop as long we exceeded the END bound.
        while(dateTime.isBefore(END)) {
            dateList.add(dateTime);
            dateTime = dateTime.plus(interval.getAmount(), interval.getInterval());
        }

        // Then check the size of the list. If it is greater than the amount of ticks, take that list.
        if (dateList.size() > noOfTicks) {
            dateTime = LocalDateTime.of(START.toLocalDate(), START.toLocalTime());
            // Recheck if the previous interval is better suited.
            while(dateTime.isBefore(END) || dateTime.isEqual(END)) {
                previousDateList.add(dateTime);
                dateTime = dateTime.plus(previousInterval.getAmount(), previousInterval.getInterval());
            }
            break;
        }

        previousInterval = interval;
    }
    if (previousDateList.size() - noOfTicks > noOfTicks - dateList.size()) {
        dateList = previousDateList;
        currentInterval = previousInterval;
    }

    // At last add the END bound.
    dateList.add(END);

    List<LocalDateTime> evenDateList = makeDatesEven(dateList, dateTime);
    // If there are at least three dates, check if the gap between the START date and the second date is at least half the gap of the second and third date.
    // Do the same for the END bound.
    // If gaps between dates are to small, remove one of them.
    // This can occur, e.g. if the START bound is 25.12.2013 and years are shown. Then the next year shown would be 2014 (01.01.2014) which would be too narrow to 25.12.2013.
    if (evenDateList.size() > 2) {
        LocalDateTime secondDate       = evenDateList.get(1);
        LocalDateTime thirdDate        = evenDateList.get(2);
        LocalDateTime lastDate         = evenDateList.get(dateList.size() - 2);
        LocalDateTime previousLastDate = evenDateList.get(dateList.size() - 3);

        // If the second date is too near by the START bound, remove it.
        if (secondDate.toEpochSecond(ZoneOffset.ofHours(0)) - START.toEpochSecond(ZoneOffset.ofHours(0)) < thirdDate.toEpochSecond(ZoneOffset.ofHours(0)) - secondDate.toEpochSecond(ZoneOffset.ofHours(0))) {
            evenDateList.remove(secondDate);
        }

        // If difference from the END bound to the last date is less than the half of the difference of the previous two dates,
        // we better remove the last date, as it comes to close to the END bound.
        if (END.toEpochSecond(ZoneOffset.ofHours(0)) - lastDate.toEpochSecond(ZoneOffset.ofHours(0)) < ((lastDate.toEpochSecond(ZoneOffset.ofHours(0)) - previousLastDate.toEpochSecond(ZoneOffset.ofHours(0)) * 0.5))) {
            evenDateList.remove(lastDate);
        }
    }
    return evenDateList;
}
 
Example 18
Source File: RUM.java    From raygun4android with MIT License 4 votes vote down vote up
/**
 * Sends a RUM event to Raygun. The message is sent on a background thread.
 *
 * @param eventName Tracks if this is a session start or session end event.
 */
private static void sendRUMEvent(String eventName, RaygunUserInfo userInfo) {

    if (RaygunClient.isRUMEnabled()) {

        String timestamp;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            LocalDateTime utcDateTime = LocalDateTime.now(ZoneId.of("UTC"));
            if (RaygunSettings.RUM_EVENT_SESSION_END.equals(eventName)) {
                utcDateTime.plus(2, ChronoUnit.SECONDS);
            }
            timestamp = utcDateTime.toString();
        } else {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            Calendar c = Calendar.getInstance();
            if (RaygunSettings.RUM_EVENT_SESSION_END.equals(eventName)) {
                c.add(Calendar.SECOND, 2);
            }
            timestamp = df.format(c.getTime());
        }

        RaygunUserInfo user = userInfo == null ? new RaygunUserInfo(null, null, null, null) : userInfo;

        RaygunRUMDataMessage dataMessage = new RaygunRUMDataMessage.Builder(eventName)
            .timestamp(timestamp)
            .sessionId(sessionId)
            .version(RaygunClient.getVersion())
            .os("Android")
            .osVersion(Build.VERSION.RELEASE)
            .platform(String.format("%s %s", Build.MANUFACTURER, Build.MODEL))
            .user(user)
            .build();

        RaygunRUMMessage message = new RaygunRUMMessage();
        message.setEventData(new RaygunRUMDataMessage[]{dataMessage});

        enqueueWorkForRUMService(RaygunClient.getApiKey(), new Gson().toJson(message));
    } else {
        RaygunLogger.w("RUM is not enabled, please enable to use the sendRUMEvent() function");
    }
}
 
Example 19
Source File: FloatingpointDate.java    From finmath-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Convert a floating point date to a LocalDateTime.
 *
 * Note: This method currently performs a rounding to the next second.
 *
 * If referenceDate is null, the method returns null.
 *
 * @param referenceDate The reference date associated with \( t=0 \).
 * @param floatingPointDate The value to the time offset \( t \).
 * @return The date resulting from adding Math.round(fixingTime*SECONDS_PER_DAY) seconds to referenceDate, where one day has SECONDS_PER_DAY seconds and SECONDS_PER_DAY is a constant 365*24*60*60
 */
public static LocalDateTime getDateFromFloatingPointDate(final LocalDateTime referenceDate, final double floatingPointDate) {
	if(referenceDate == null) {
		return null;
	}

	final Duration duration = Duration.ofSeconds(Math.round(floatingPointDate * SECONDS_PER_DAY));
	return referenceDate.plus(duration);
}
 
Example 20
Source File: LocalDateTimeUtil.java    From utils with Apache License 2.0 2 votes vote down vote up
/**
 * 日期加上一个数,根据field不同加不同值,field为ChronoUnit.*.
 *
 * @param time
 * @param number
 * @param field
 * @return java.time.LocalDateTime
 */
public static LocalDateTime plus(LocalDateTime time, long number, TemporalUnit field) {
    return time.plus(number, field);
}