Example usage for org.joda.time DateTimeZone getStandardOffset

List of usage examples for org.joda.time DateTimeZone getStandardOffset

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone getStandardOffset.

Prototype

public abstract int getStandardOffset(long instant);

Source Link

Document

Gets the raw millisecond offset to add to UTC.

Usage

From source file:org.thelq.pircbotx.commands.NewYearsCommand.java

License:Open Source License

public static String getUTCOffset(DateTimeZone tz) {
    long millis = System.currentTimeMillis();
    while (tz.getOffset(millis) != tz.getStandardOffset(millis)) {
        long next = tz.nextTransition(millis);
        if (next == millis)
            break;
        millis = next;//  ww w .j  a  va  2s .  c  o  m
    }
    return "UTC" + FORMATTER_TZOFFSET.withZone(tz).print(millis);
}

From source file:org.zanata.dao.TextFlowTargetHistoryDAO.java

License:Open Source License

private static String getOffsetAsString(DateTimeZone zone) {
    int standardOffset = zone.getStandardOffset(0);
    String prefix = "";
    if (standardOffset < 0) {
        prefix = "-";
        standardOffset = -standardOffset;
    }/*from   w  ww  .  j  a  va2 s  .c  om*/
    return String.format("%s%02d:00", prefix, TimeUnit.MILLISECONDS.toHours(standardOffset));
}

From source file:org.zanata.rest.service.StatisticsServiceImpl.java

License:Open Source License

/**
 * Get translation work statistics for a user in given date range.
 *
 * Throws NoSuchEntityException if: - user not found
 *
 * Throws InvalidDateParamException if: - dateRangeParam is in wrong format,
 * - date range is over MAX_STATS_DAYS/*from w  ww.  j  a va2  s.  co m*/
 *
 * @param username
 *            username of contributor
 * @param dateRangeParam
 *            from..to (yyyy-mm-dd..yyyy-mm-dd), date range maximum: 365
 *            days
 * @param userTimeZoneID
 *            optional user time zone ID. Will use system default in absence
 *            or GMT zone if provided time zone ID can not be understood.
 */
@Path("user/{username}/{dateRangeParam}")
@GET
@Produces({ "application/json" })
public List<TranslationMatrix> getUserWorkMatrix(@PathParam("username") final String username,
        @PathParam("dateRangeParam") String dateRangeParam, @QueryParam("userTimeZone") String userTimeZoneID) {
    HPerson person = findPersonOrExceptionOnNotFound(username);
    DateRange dateRange = DateRange.from(dateRangeParam, userTimeZoneID);
    DateTime fromDate = dateRange.getFromDate();
    DateTime toDate = dateRange.getToDate();

    DateTimeZone userZone = dateRange.getTimeZone();
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(DATE_FORMAT).withZone(userZone);

    // TODO system time zone should be persisted in database
    DateTimeZone systemZone = DateTimeZone.getDefault();

    Optional<DateTimeZone> userZoneOpt;
    if (userZone.getStandardOffset(0) != systemZone.getStandardOffset(0)) {
        userZoneOpt = Optional.of(userZone);
    } else {
        userZoneOpt = Optional.absent();
    }

    List<TranslationMatrix> translationMatrixList = textFlowTargetHistoryDAO.getUserTranslationMatrix(person,
            fromDate, toDate, userZoneOpt, systemZone,
            new UserMatrixResultTransformer(entityManager, dateFormatter));

    return translationMatrixList;
}