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:com.qcadoo.mes.productionPerShift.PpsTimeHelper.java

License:Open Source License

public Date findFinishDate(final Entity dailyProgress, Date dateOfDay, Entity order) {
    DateTime endDate = null;/*  w w  w. j av a 2s  .  c  om*/
    DateTime dateOfDayDT = new DateTime(dateOfDay, DateTimeZone.getDefault());
    DateTime orderStartDate = new DateTime(order.getDateField(OrderFields.START_DATE),
            DateTimeZone.getDefault());
    Entity shiftEntity = dailyProgress.getBelongsToField(DailyProgressFields.SHIFT);
    Shift shift = new Shift(shiftEntity);
    List<TimeRange> shiftWorkTime = Lists.newArrayList();
    List<DateTimeRange> shiftWorkDateTime = Lists.newArrayList();
    if (shift.worksAt(dateOfDay.getDay() == 0 ? 7 : dateOfDay.getDay())) {
        shiftWorkTime = shift.findWorkTimeAt(new LocalDate(dateOfDay));
    }
    for (TimeRange range : shiftWorkTime) {
        DateTimeRange dateTimeRange = new DateTimeRange(dateOfDayDT, range);
        DateTimeRange trimmedRange = dateTimeRange.trimBefore(orderStartDate);
        if (trimmedRange != null) {
            shiftWorkDateTime.add(trimmedRange);
        }
    }

    shiftWorkDateTime = manageExceptions(shiftWorkDateTime, shift.getEntity(), dateOfDay);

    for (DateTimeRange range : shiftWorkDateTime) {
        if (endDate == null || endDate.isBefore(range.getTo())) {
            endDate = range.getTo();
        }
    }
    return endDate.toDate();
}

From source file:com.ryan.ryanreader.common.RRTime.java

License:Open Source License

public static String formatDateTime(final long utc_ms, final Context context) {

    final DateTime dateTime = new DateTime(utc_ms);
    final DateTime localDateTime = dateTime.withZone(DateTimeZone.getDefault());

    if (DateFormat.is24HourFormat(context)) {
        return dtFormatter24hr.print(localDateTime);
    } else {/*from  ww  w . j  a  va 2 s . com*/
        return dtFormatter12hr.print(localDateTime);
    }
}

From source file:com.sandata.lab.common.utils.date.DateUtil.java

License:Open Source License

public static Date ConvertDateToUTC(Date localDate) throws ParseException {
    DateTimeZone tz = DateTimeZone.getDefault();
    Date utcDate = new Date(tz.convertLocalToUTC(localDate.getTime(), false));
    return utcDate;
}

From source file:com.sonicle.webtop.core.app.WebTopApp.java

License:Open Source License

WebTopApp(ServletContext servletContext) {
    WebTopApp.webappName = ContextUtils.getWebappFullName(servletContext, false);
    this.servletContext = servletContext;

    this.osInfo = OSInfo.build();
    this.systemCharset = Charset.forName("UTF-8");
    this.systemTimeZone = DateTimeZone.getDefault();

    // Ignore SSL checks for old commons-http components.
    // This is required in order to avoid error when accessing WebDAV 
    // secured servers throught vfs2.
    Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443));

    System.setProperty("net.fortuna.ical4j.timezone.update.enabled", "false");
    //System.setProperty("mail.mime.address.strict", "false"); // If necessary set using -D
    System.setProperty("mail.mime.decodetext.strict", "false");
    System.setProperty("mail.mime.decodefilename", "true");

    ICalendarUtils.setUnfoldingRelaxed(true);
    ICalendarUtils.setParsingRelaxed(true);
    ICalendarUtils.setValidationRelaxed(true);
    ICalendarUtils.setCompatibilityOutlook(true);
    ICalendarUtils.setCompatibilityNotes(true);

    Properties systemProps = System.getProperties();
    WebTopProps.checkOldPropsUsage(systemProps);
    WebTopProps.print(systemProps);/*  w w  w  . ja v  a 2s .  co  m*/

    //logger.info("getContextPath: {}", context.getContextPath());
    //logger.info("getServletContextName: {}", context.getServletContextName());
    //logger.info("getVirtualServerName: {}", context.getVirtualServerName());

    String configDir = WebTopProps.getWebappsConfigDir(systemProps);
    if (StringUtils.isBlank(configDir)) {
        this.webappConfigPath = null;
    } else {
        this.webappConfigPath = PathUtils.concatPaths(configDir,
                ContextUtils.getWebappFullName(servletContext, true));
    }
    this.shiroSecurityManager = buildSecurityManager();
    this.adminSubject = buildSysAdminSubject(shiroSecurityManager);
}

From source file:com.sonicle.webtop.core.sdk.BaseSettings.java

License:Open Source License

public LocalTime getTime(String key, String defaultValue, String pattern) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.getDefault());
    LocalTime lt = (defaultValue == null) ? null : LocalTime.parse(defaultValue, dtf);
    return getTime(key, lt, pattern);
}

From source file:com.sonicle.webtop.core.sdk.BaseSettings.java

License:Open Source License

public LocalDate getDate(String key, String defaultValue, String pattern) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.getDefault());
    LocalDate lt = (defaultValue == null) ? null : LocalDate.parse(defaultValue, dtf);
    return getDate(key, lt, pattern);
}

From source file:com.sonicle.webtop.core.sdk.BaseSettings.java

License:Open Source License

public LocalDate getDate(String key, LocalDate defaultValue, String pattern) {
    DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.getDefault());
    String value = getString(key, null);
    return (value == null) ? defaultValue : LocalDate.parse(value, dtf);
}

From source file:com.springsource.greenhouse.home.DateTimeZoneHandlerInterceptor.java

License:Apache License

private DateTimeZone getTimeZone(HttpServletRequest request) {
    Integer millisOffset = getMillisOffset(request);
    if (millisOffset != null) {
        try {//from w  ww. ja v a2s  . c  o  m
            return DateTimeZone.forOffsetMillis(millisOffset);
        } catch (IllegalArgumentException e) {
            return DateTimeZone.getDefault();
        }
    } else {
        return DateTimeZone.getDefault();
    }
}

From source file:com.squarespace.template.plugins.PluginDateUtils.java

License:Apache License

public static boolean sameDay(long instant1, long instant2, String tzName) {
    DateTimeZone zone = null;//w w  w .j  a va 2s  . c  o  m
    try {
        zone = DateTimeZone.forID(tzName);
    } catch (IllegalArgumentException e) {
        zone = DateTimeZone.getDefault();
    }
    DateTime date1 = new DateTime(instant1, zone);
    DateTime date2 = new DateTime(instant2, zone);
    return (date1.year().get() == date2.year().get())
            && (date1.monthOfYear().get() == date2.monthOfYear().get())
            && (date1.dayOfMonth().get() == date2.dayOfMonth().get());
}

From source file:com.squarespace.template.plugins.PluginDateUtils.java

License:Apache License

/**
 * Takes a strftime()-compatible format string and outputs the properly formatted date.
 *///from   ww w . j  a  v a 2 s.  c  o  m
public static void formatDate(Locale locale, String fmt, long instant, String tzName, StringBuilder buf) {
    DateTimeZone zone = null;
    try {
        zone = DateTimeZone.forID(tzName);
    } catch (IllegalArgumentException e) {
        zone = DateTimeZone.getDefault();
    }
    DateTime date = new DateTime(instant, zone);
    int index = 0;
    int len = fmt.length();
    while (index < len) {
        char c1 = fmt.charAt(index);
        index++;
        if (c1 != '%' || index == len) {
            buf.append(c1);
            continue;
        }
        char c2 = fmt.charAt(index);
        switch (c2) {
        case 'A':
            buf.append(date.dayOfWeek().getAsText(locale));
            break;
        case 'a':
            buf.append(date.dayOfWeek().getAsShortText(locale));
            break;
        case 'B':
            buf.append(date.monthOfYear().getAsText(locale));
            break;
        case 'b':
            buf.append(date.monthOfYear().getAsShortText(locale));
            break;
        case 'C':
            leftPad(date.centuryOfEra().get(), '0', 2, buf);
            break;
        case 'c':
            formatAggregate(DateTimeAggregate.FULL, locale, date, buf);
            break;
        case 'D':
            formatAggregate(DateTimeAggregate.MMDDYY, locale, date, buf);
            break;
        case 'd':
            leftPad(date.dayOfMonth().get(), '0', 2, buf);
            break;
        case 'e':
            leftPad(date.dayOfMonth().get(), ' ', 2, buf);
            break;
        case 'F':
            formatAggregate(DateTimeAggregate.YYYYMMDD, locale, date, buf);
            break;
        case 'G':
            buf.append(date.year().get());
            break;
        case 'g':
            leftPad(date.yearOfCentury().get(), '0', 2, buf);
            break;
        case 'H':
            leftPad(date.hourOfDay().get(), '0', 2, buf);
            break;
        case 'h':
            buf.append(date.monthOfYear().getAsShortText(locale));
            break;
        case 'I':
            leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), '0', 2, buf);
            break;
        case 'j':
            leftPad(date.dayOfYear().get(), '0', 3, buf);
            break;
        case 'k':
            leftPad(date.get(DateTimeFieldType.clockhourOfDay()), ' ', 2, buf);
            break;
        case 'l':
            leftPad(date.get(DateTimeFieldType.clockhourOfHalfday()), ' ', 2, buf);
            break;
        case 'M':
            leftPad(date.minuteOfHour().get(), '0', 2, buf);
            break;
        case 'm':
            leftPad(date.monthOfYear().get(), '0', 2, buf);
            break;
        case 'n':
            buf.append('\n');
            break;
        case 'P':
            buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "am" : "pm");
            break;
        case 'p':
            buf.append(date.get(DateTimeFieldType.halfdayOfDay()) == 0 ? "AM" : "PM");
            break;
        case 'R':
            formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf);
            break;
        case 'S':
            leftPad(date.secondOfMinute().get(), '0', 2, buf);
            break;
        case 's':
            buf.append(instant / 1000);
            break;
        case 't':
            buf.append('\t');
            break;
        case 'T':
            // Equivalent of %H:%M:%S
            formatAggregate(DateTimeAggregate.H240_M0, locale, date, buf);
            buf.append(':');
            leftPad(date.secondOfMinute().get(), '0', 2, buf);
            break;

        case 'U':
            // TODO: fix week-of-year number
            leftPad(date.weekOfWeekyear().get(), '0', 2, buf);
            break;

        case 'u':
            buf.append(date.dayOfWeek().get());
            break;

        case 'V':
            // TODO: fix week-of-year number
            leftPad(date.weekOfWeekyear().get(), '0', 2, buf);
            break;

        case 'v':
            // Equivalent of %e-%b-%Y
            leftPad(date.dayOfMonth().get(), ' ', 2, buf);
            buf.append('-');
            buf.append(date.monthOfYear().getAsShortText());
            buf.append('-');
            buf.append(date.getYear());
            break;

        case 'W':
            // TODO: fix week-of-year number
            break;

        case 'w':
            buf.append(date.dayOfWeek().get());
            break;
        case 'X':
            formatAggregate(DateTimeAggregate.HHMMSSP, locale, date, buf);
            break;
        case 'x':
            formatAggregate(DateTimeAggregate.MMDDYYYY, locale, date, buf);
            break;
        case 'Y':
            buf.append(date.getYear());
            break;
        case 'y':
            leftPad(date.getYearOfCentury(), '0', 2, buf);
            break;

        case 'Z':
            // Note: Joda's nameKey happens to be the same as the shortName. Making
            // this change to workaround Joda https://github.com/JodaOrg/joda-time/issues/288
            buf.append(zone.getNameKey(date.getMillis()));
            break;

        case 'z':
            int offset = date.getZone().getOffset(instant) / 60000;
            int hours = (int) Math.floor(offset / 60);
            int minutes = (hours * 60) - offset;
            if (offset < 0) {
                buf.append('-');
            }
            leftPad(Math.abs(hours), '0', 2, buf);
            leftPad(Math.abs(minutes), '0', 2, buf);
            break;

        default:
            // no match, emit literals.
            buf.append(c1).append(c2);
        }
        index++;
    }
}