Example usage for org.joda.time DateTimeZone getDefault

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

Introduction

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

Prototype

public static DateTimeZone getDefault() 

Source Link

Document

Gets the default time zone.

Usage

From source file:org.wicketopia.joda.util.format.JodaFormatSupport.java

License:Apache License

/**
 * Gets the server time zone. Override this method if you want to fix to a certain time zone,
 * regardless of what actual time zone the server is in.
 *
 * @return The server time zone//  ww w.j av  a 2  s.  co m
 */
private static DateTimeZone getServerTimeZone() {
    return DateTimeZone.getDefault();
}

From source file:org.wso2.carbon.bpmn.people.substitution.UserSubstitutionUtils.java

License:Open Source License

private static Date getEndTimeMaxDate() {
    DateTime dateTime = new DateTime(SubstitutionDataHolder.getInstance().getSubstitutionMaxEpoch(),
            DateTimeZone.UTC);/*from   w w w  .j a va 2  s  . co m*/
    Date maxDate = new Date(dateTime.toDateTime(DateTimeZone.getDefault()).getMillis());
    return maxDate;
}

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/*  w  w  w . java2  s. c  o 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;
}

From source file:pl.aptekhurt.service.PharmacyOrderService.java

public void createPharmacyOrder(List<NewPharmacyOrderDTO> productOrderDTOs, Principal principal) {
    for (NewPharmacyOrderDTO productOrderDTO : productOrderDTOs) {
        Pharmacy_order pharmacy_order = new Pharmacy_order();
        Product_option productOption = product_optionRepository.getOne(productOrderDTO.getProductOptionId());
        pharmacy_order.setProduct_Option(productOption);
        pharmacy_order.setQuantity(productOrderDTO.getQuantity());
        pharmacy_order.setCreation_date(new DateTime(DateTimeZone.getDefault()));
        DateTime temporaryDateTime = new DateTime(DateTimeZone.getDefault());
        switch (productOrderDTO.getTermin()) {
        case 1:/*from   ww w. j a  v a 2  s  . c o m*/
            temporaryDateTime = new DateTime().dayOfMonth().withMinimumValue().withTimeAtStartOfDay();
            break;
        case 16:
            temporaryDateTime = new DateTime().withDayOfMonth(16).withTimeAtStartOfDay();
            break;
        }
        if (temporaryDateTime.isBeforeNow()) {
            temporaryDateTime = temporaryDateTime.plusMonths(1);
        }
        pharmacy_order.setTermin(temporaryDateTime);
        Pharmacy pharmacy = userRepository.findOneByLogin(principal.getName()).get().getPharmacy();
        pharmacy_order.setPharmacy(pharmacy);
        log.debug("REST request to save Pharmacy_order : {}", pharmacy_order);
        if (hasNewLimitBeenReached(productOption, productOrderDTO.getQuantity())) {
            if (ADMIN_USER == null) {
                ADMIN_USER = userRepository.findOneByLogin("admin").get();
            }
            mailService.sendNewLimitReachedEmail(ADMIN_USER, productOption,
                    pharmacy_order.getQuantity() + productOrderDTO.getQuantity());
        }
        pharmacy_orderRepository.save(pharmacy_order);
    }
    //TODO: Send email with all that products
}

From source file:r.base.time.Time.java

License:Open Source License

/**
 * Formats a Posix-lt time as a string./*from  w  w  w. j  a v  a 2 s  .c o  m*/
 * @param x
 * @param format
 * @param useTz
 * @return
 */
@Primitive("format.POSIXlt")
public static StringVector formatPOSIXlt(ListVector x, StringVector patterns, boolean useTz) {

    PosixLtVector dateTimes = new PosixLtVector(x);
    List<DateTimeFormatter> formatters = DateTimeFormat.forPatterns(patterns, DateTimeZone.getDefault(), useTz);

    StringVector.Builder result = new StringVector.Builder();
    int resultLength = Math.max(dateTimes.length(), patterns.length());

    for (int i = 0; i != resultLength; ++i) {
        DateTimeFormatter formatter = formatters.get(i % formatters.size());
        DateTime dateTime = dateTimes.getElementAsDateTime(i % dateTimes.length());

        result.add(formatter.print(dateTime));
    }

    return result.build();
}

From source file:se.jguru.nazgul.test.xmlbinding.junit.StandardTimeZoneRule.java

License:Apache License

/**
 * Constructor creating a new StandardTimeZoneRule which will set the provided desiredTimeZone
 * for use during the jUnit test.//from   w w  w  .  j ava2  s .c o  m
 *
 * @param desiredTimeZone The non-null DateTimeZone which should be used during the test.
 */
public StandardTimeZoneRule(final DateTimeZone desiredTimeZone) {

    // Check sanity
    Validate.notNull(desiredTimeZone, "Cannot handle null desiredTimeZone argument.");

    // Stash the default DateTimeZone, and reassign the default one.
    originalTimeZone = DateTimeZone.getDefault();
    this.desiredTimeZone = desiredTimeZone;
}

From source file:se.softhouse.jargo.addons.Arguments.java

License:Apache License

/**
 * Creates an {@link Argument} that parses {@link DateTime dates} with the
 * {@link DateTimeZone#getDefault() default timezone} and the
 * {@link ISODateTimeFormat#dateOptionalTimeParser()}.
 *
 * @param names the {@link ArgumentBuilder#names(String...) names} to use
 *///  w  w  w .  ja  v  a  2 s . co m
public static DefaultArgumentBuilder<DateTime> dateArgument(String... names) {
    return se.softhouse.jargo.Arguments.withParser(new DateTimeParser(DateTimeZone.getDefault()))
            .defaultValueDescription("Current time").names(names);
}

From source file:stroom.dashboard.server.format.DateFormatter.java

License:Apache License

public static DateFormatter create(final FormatSettings settings, final String dateTimeLocale) {
    org.joda.time.format.DateTimeFormatter format = null;

    if (settings != null && settings instanceof DateTimeFormatSettings) {
        final DateTimeFormatSettings dateTimeFormatSettings = (DateTimeFormatSettings) settings;
        String pattern = dateTimeFormatSettings.getPattern();
        if (pattern != null && pattern.trim().length() > 0) {
            final TimeZone timeZone = dateTimeFormatSettings.getTimeZone();
            DateTimeZone zone = DateTimeZone.UTC;

            if (timeZone != null) {
                if (TimeZone.Use.UTC.equals(timeZone.getUse())) {
                    zone = DateTimeZone.UTC;
                } else if (TimeZone.Use.LOCAL.equals(timeZone.getUse())) {
                    pattern = pattern.replaceAll("'Z'", "Z");
                    zone = DateTimeZone.getDefault();

                    try {
                        if (dateTimeLocale != null) {
                            zone = DateTimeZone.forID(dateTimeLocale);
                        }//  w w  w . j  av a 2  s.  co m
                    } catch (final IllegalArgumentException e) {
                        // The client time zone was not recognised so we'll
                        // use the default.
                    }

                } else if (TimeZone.Use.ID.equals(timeZone.getUse())) {
                    pattern = pattern.replaceAll("'Z'", "Z");
                    zone = DateTimeZone.forID(timeZone.getId());
                } else if (TimeZone.Use.OFFSET.equals(timeZone.getUse())) {
                    pattern = pattern.replaceAll("'Z'", "Z");
                    zone = DateTimeZone.forOffsetHoursMinutes(getInt(timeZone.getOffsetHours()),
                            getInt(timeZone.getOffsetMinutes()));
                }
            }

            format = DateTimeFormat.forPattern(pattern).withZone(zone);
        }
    }

    return new DateFormatter(format);
}

From source file:uk.ac.ucl.excites.sapelli.storage.types.TimeStamp.java

License:Apache License

/** 
 * @param timestamp/*from   w w  w .j av a2 s  .c  om*/
 * @return return the same timestamp but with the device/local/default timezone
 */
static public TimeStamp setLocalTimeZone(TimeStamp timestamp) {
    return timestamp == null ? null : new TimeStamp(timestamp.getMsSinceEpoch(), DateTimeZone.getDefault());
}