Example usage for org.joda.time PeriodType dayTime

List of usage examples for org.joda.time PeriodType dayTime

Introduction

In this page you can find the example usage for org.joda.time PeriodType dayTime.

Prototype

public static PeriodType dayTime() 

Source Link

Document

Gets a type that defines all standard fields from days downwards.

Usage

From source file:com.metinkale.prayerapp.vakit.times.Times.java

License:Apache License

public String getLeft(int next, boolean showsecs) {
    LocalDateTime date = getTimeCal(null, next);
    Period period = new Period(LocalDateTime.now(), date, PeriodType.dayTime());

    if (showsecs) {
        return Utils.toArabicNrs(PERIOD_FORMATTER_HMS.print(period));
    } else if (Prefs.isDefaultWidgetMinuteType()) {
        return Utils.toArabicNrs(PERIOD_FORMATTER_HM.print(period));
    } else {/* w w w . ja  va2  s . c  om*/
        period = period.withFieldAdded(DurationFieldType.minutes(), 1);
        return Utils.toArabicNrs(PERIOD_FORMATTER_HM.print(period));
    }

}

From source file:com.thinkbiganalytics.scheduler.util.TimerToCronExpression.java

License:Apache License

/**
 * Parse a timer string to a Joda time period
 *//*from w  ww.j  av a 2  s  .  c o m*/
public static Period timerStringToPeriod(String timer) {
    return timerStringToPeriod(timer, PeriodType.dayTime());
}

From source file:eu.vranckaert.worktime.activities.account.AccountProfileActivity.java

License:Apache License

private void updateUI(User user) {
    profileContainer.setVisibility(View.VISIBLE);

    email.setText(user.getEmail());/* w  ww  .  j a v  a2  s. c  o m*/
    name.setText(user.getFirstName() + " " + user.getLastName());
    registeredSince.setText(DateUtils.DateTimeConverter.convertDateTimeToString(user.getRegisteredSince(),
            DateFormat.MEDIUM, TimeFormat.MEDIUM, AccountProfileActivity.this));

    String loggedInSinceText = DateUtils.DateTimeConverter.convertDateTimeToString(user.getLoggedInSince(),
            DateFormat.MEDIUM, TimeFormat.MEDIUM, AccountProfileActivity.this);
    String loggedInDurationText = DateUtils.TimeCalculator.calculateDuration(AccountProfileActivity.this,
            user.getLoggedInSince(), new Date(), PeriodType.dayTime());

    loggedInSince.setText(loggedInSinceText + " (" + loggedInDurationText + ")");
}

From source file:eu.vranckaert.worktime.activities.account.AccountProfileActivity.java

License:Apache License

private void updateUI(SyncHistory syncHistory) {
    if (syncHistory == null) {
        syncHistoryContainer.setVisibility(View.GONE);
        return;/*from  w  w w  . jav  a 2 s  .  co m*/
    }

    syncHistoryContainer.setVisibility(View.VISIBLE);

    String startTimeText = DateUtils.DateTimeConverter.convertDateTimeToString(syncHistory.getStarted(),
            DateFormat.MEDIUM, TimeFormat.MEDIUM, AccountProfileActivity.this);
    String durationText = DateUtils.TimeCalculator.calculateDuration(AccountProfileActivity.this,
            syncHistory.getStarted(), new Date(), PeriodType.dayTime());
    syncHistoryStartTime.setText(startTimeText + " (" + durationText + ")");

    if (syncHistory.getEnded() != null)
        syncHistoryEndTime.setText(DateUtils.DateTimeConverter.convertDateTimeToString(syncHistory.getEnded(),
                DateFormat.MEDIUM, TimeFormat.MEDIUM, AccountProfileActivity.this));

    syncHistoryReasonLabel.setVisibility(View.GONE);
    syncHistoryReason.setVisibility(View.GONE);

    switch (syncHistory.getStatus()) {
    case SUCCESSFUL:
        syncHistoryResolution.setText(R.string.lbl_account_sync_resolution_successful);
        break;
    case INTERRUPTED:
        syncHistoryResolution.setText(R.string.lbl_account_sync_resolution_interrupted);
        syncHistoryReasonLabel.setVisibility(View.VISIBLE);
        syncHistoryReason.setText(R.string.lbl_account_sync_history_reason_interruption);
        syncHistoryReason.setVisibility(View.VISIBLE);
        break;
    case FAILED:
        syncHistoryResolution.setText(R.string.lbl_account_sync_resolution_failed);
        if (StringUtils.isNotBlank(syncHistory.getFailureReason())) {
            syncHistoryReasonLabel.setVisibility(View.VISIBLE);
            syncHistoryReason.setText(syncHistory.getFailureReason());
            syncHistoryReason.setVisibility(View.VISIBLE);
        }
        break;
    case TIMED_OUT:
        syncHistoryResolution.setText(R.string.lbl_account_sync_resolution_timed_out);
        break;
    case BUSY:
        syncHistoryResolution.setText(R.string.lbl_account_sync_resolution_busy);
        break;
    }
}

From source file:google.registry.export.CheckSnapshotAction.java

License:Open Source License

private void checkAndLoadSnapshotIfComplete() {
    Set<String> kindsToLoad = ImmutableSet.copyOf(Splitter.on(',').split(kindsToLoadParam));
    DatastoreBackupInfo backup = getBackup();
    // Stop now if the backup is not complete.
    if (!backup.getStatus().equals(BackupStatus.COMPLETE)) {
        Duration runningTime = backup.getRunningTime();
        if (runningTime.isShorterThan(MAXIMUM_BACKUP_RUNNING_TIME)) {
            // Backup might still be running, so send a 304 to have the task retry.
            throw new NotModifiedException(String.format("Datastore backup %s still pending", snapshotName));
        } else {//from   w w w . j  av  a 2  s . c  om
            // Declare the backup a lost cause, and send 204 No Content so the task will
            // not be retried.
            String message = String.format("Datastore backup %s abandoned - not complete after %s",
                    snapshotName, PeriodFormat.getDefault().print(runningTime.toPeriod()
                            .normalizedStandard(PeriodType.dayTime().withMillisRemoved())));
            throw new NoContentException(message);
        }
    }
    // Get a compact string to identify this snapshot in BigQuery by trying to parse the unique
    // suffix out of the snapshot name and falling back to the start time as a string.
    String snapshotId = snapshotName.startsWith(ExportSnapshotAction.SNAPSHOT_PREFIX)
            ? snapshotName.substring(ExportSnapshotAction.SNAPSHOT_PREFIX.length())
            : backup.getStartTime().toString("YYYYMMdd_HHmmss");
    // Log a warning if kindsToLoad is not a subset of the exported snapshot kinds.
    if (!backup.getKinds().containsAll(kindsToLoad)) {
        logger.warningfmt("Kinds to load included non-exported kinds: %s",
                Sets.difference(kindsToLoad, backup.getKinds()));
    }
    // Load kinds from the snapshot, limited to those also in kindsToLoad (if it's present).
    ImmutableSet<String> exportedKindsToLoad = ImmutableSet
            .copyOf(intersection(backup.getKinds(), kindsToLoad));
    String message = String.format("Datastore backup %s complete - ", snapshotName);
    if (exportedKindsToLoad.isEmpty()) {
        message += "no kinds to load into BigQuery";
    } else {
        enqueueLoadSnapshotTask(snapshotId, backup.getGcsFilename().get(), exportedKindsToLoad);
        message += "BigQuery load task enqueued";
    }
    logger.info(message);
    response.setPayload(message);
}

From source file:google.registry.export.CheckSnapshotServlet.java

License:Open Source License

@Override
public void doPost(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
    String snapshotName;/*from  www  . j  a va 2 s  .c  om*/
    String kindsToLoadParam;
    // TODO(b/28266757): Remove this try/catch/rethrow block once this servlet is Daggerized.
    try {
        snapshotName = extractRequiredParameter(req, SNAPSHOT_NAME_PARAM);
        kindsToLoadParam = extractRequiredParameter(req, SNAPSHOT_KINDS_TO_LOAD_PARAM);
    } catch (BadRequestException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
    Set<String> kindsToLoad = ImmutableSet.copyOf(Splitter.on(',').split(kindsToLoadParam));

    // Look up the backup by the provided name, stopping if we can't find it.
    DatastoreBackupInfo backup;
    try {
        backup = backupService.findByName(snapshotName);
    } catch (IllegalArgumentException e) {
        String message = String.format("Bad backup name %s: %s", snapshotName, e.getMessage());
        logger.severe(e, message);
        // TODO(b/19081569): Ideally this would return a 2XX error so the task would not be retried,
        //   but we might abandon backups that start late and haven't yet written to datastore.
        //   We could fix that by replacing this with a two-phase polling strategy.
        rsp.sendError(SC_BAD_REQUEST, htmlEscaper().escape(message));
        return;
    }
    // Stop now if the backup is not complete.
    if (!backup.getStatus().equals(BackupStatus.COMPLETE)) {
        Duration runningTime = backup.getRunningTime();
        if (runningTime.isShorterThan(MAXIMUM_BACKUP_RUNNING_TIME)) {
            // Backup might still be running, so send a 304 to have the task retry.
            rsp.sendError(SC_NOT_MODIFIED,
                    htmlEscaper().escape(String.format("Datastore backup %s still pending", snapshotName)));
        } else {
            // Declare the backup a lost cause, and send 202 Accepted so the task will not be retried.
            String message = String.format("Datastore backup %s abandoned - not complete after %s",
                    snapshotName, PeriodFormat.getDefault().print(runningTime.toPeriod()
                            .normalizedStandard(PeriodType.dayTime().withMillisRemoved())));
            logger.severe(message);
            rsp.sendError(SC_ACCEPTED, htmlEscaper().escape(message));
        }
        return;
    }
    // Get a compact string to identify this snapshot in BigQuery by trying to parse the unique
    // suffix out of the snapshot name and falling back to the start time as a string.
    String snapshotId = snapshotName.startsWith(ExportSnapshotServlet.SNAPSHOT_PREFIX)
            ? snapshotName.substring(ExportSnapshotServlet.SNAPSHOT_PREFIX.length())
            : backup.getStartTime().toString("YYYYMMdd_HHmmss");
    // Log a warning if kindsToLoad is not a subset of the exported snapshot kinds.
    if (!backup.getKinds().containsAll(kindsToLoad)) {
        logger.warningfmt("Kinds to load included non-exported kinds: %s",
                Sets.difference(kindsToLoad, backup.getKinds()));
    }
    // Load kinds from the snapshot, limited to those also in kindsToLoad (if it's present).
    ImmutableSet<String> exportedKindsToLoad = ImmutableSet
            .copyOf(intersection(backup.getKinds(), kindsToLoad));
    String message = String.format("Datastore backup %s complete - ", snapshotName);
    if (exportedKindsToLoad.isEmpty()) {
        message += "no kinds to load into BigQuery";
    } else {
        enqueueLoadSnapshotTask(snapshotId, backup.getGcsFilename().get(), exportedKindsToLoad);
        message += "BigQuery load task enqueued";
    }
    logger.info(message);
    rsp.getWriter().write(message);
}

From source file:net.bashtech.geobot.MessageReplaceParser.java

License:Open Source License

public static String handleUntil(String message, String prefix, String suffix, PeriodFormatter formatter) {

    int commandStart = message.indexOf(prefix);
    int commandEnd = message.indexOf(suffix);

    if (commandStart + prefix.length() < commandEnd) {

        String replaced = message.substring(commandStart, commandEnd + suffix.length());
        String dateStr = message.substring(commandStart + prefix.length(), commandEnd);

        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm");
        String until;/*from w  w  w.  ja v a 2  s  .c om*/
        try {
            DateTime future = fmt.parseDateTime(dateStr);

            PeriodType pType = PeriodType.dayTime().withMillisRemoved().withSecondsRemoved();

            Period period = new Period(new DateTime(), future, pType);

            until = period.toString(formatter);

        } catch (IllegalArgumentException e) {
            until = "Unknown date";
            System.out.println(dateStr);
            e.printStackTrace();
        }

        message = message.replace(replaced, until);
    }
    return message;
}

From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnPeriodMapper.java

License:Apache License

private PeriodType determinePeriodType(String s) {

    PeriodType periodType = PeriodType.standard();

    String current = s;//from   w  w  w .ja  v a  2  s. c o m

    if (current.startsWith(PeriodType.standard().getName())) {
        periodType = PeriodType.standard();
        current = s.substring(PeriodType.standard().getName().length());

    } else if (current.startsWith(PeriodType.yearMonthDayTime().getName())) {
        periodType = PeriodType.yearMonthDayTime();
        current = s.substring(PeriodType.yearMonthDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearMonthDay().getName())) {
        periodType = PeriodType.yearMonthDay();
        current = s.substring(PeriodType.yearMonthDay().getName().length());

    } else if (current.startsWith(PeriodType.yearWeekDayTime().getName())) {
        periodType = PeriodType.yearWeekDayTime();
        current = s.substring(PeriodType.yearWeekDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearWeekDay().getName())) {
        periodType = PeriodType.yearWeekDay();
        current = s.substring(PeriodType.yearWeekDay().getName().length());

    } else if (current.startsWith(PeriodType.yearDayTime().getName())) {
        periodType = PeriodType.yearDayTime();
        current = s.substring(PeriodType.yearDayTime().getName().length());

    } else if (current.startsWith(PeriodType.yearDay().getName())) {
        periodType = PeriodType.yearDay();
        current = s.substring(PeriodType.yearDay().getName().length());

    } else if (current.startsWith(PeriodType.dayTime().getName())) {
        periodType = PeriodType.dayTime();
        current = s.substring(PeriodType.dayTime().getName().length());

    } else if (current.startsWith(PeriodType.time().getName())) {
        periodType = PeriodType.time();
        current = s.substring(PeriodType.time().getName().length());

    } else if (current.startsWith(PeriodType.years().getName())) {
        periodType = PeriodType.years();
        current = s.substring(PeriodType.years().getName().length());

    } else if (current.startsWith(PeriodType.months().getName())) {
        periodType = PeriodType.months();
        current = s.substring(PeriodType.months().getName().length());

    } else if (current.startsWith(PeriodType.weeks().getName())) {
        periodType = PeriodType.weeks();
        current = s.substring(PeriodType.weeks().getName().length());

    } else if (current.startsWith(PeriodType.days().getName())) {
        periodType = PeriodType.days();
        current = s.substring(PeriodType.days().getName().length());

    } else if (current.startsWith(PeriodType.hours().getName())) {
        periodType = PeriodType.hours();
        current = s.substring(PeriodType.hours().getName().length());

    } else if (current.startsWith(PeriodType.minutes().getName())) {
        periodType = PeriodType.minutes();
        current = s.substring(PeriodType.minutes().getName().length());

    } else if (current.startsWith(PeriodType.seconds().getName())) {
        periodType = PeriodType.seconds();
        current = s.substring(PeriodType.seconds().getName().length());

    } else if (current.startsWith(PeriodType.millis().getName())) {
        periodType = PeriodType.millis();
        current = s.substring(PeriodType.millis().getName().length());
    }

    while (current.length() > 0) {

        if (current.startsWith("NoYears")) {
            periodType = periodType.withYearsRemoved();
            current = s.substring("NoYears".length());
        } else if (current.startsWith("NoMonths")) {
            periodType = periodType.withMonthsRemoved();
            current = s.substring("NoMonths".length());
        } else if (current.startsWith("NoWeeks")) {
            periodType = periodType.withWeeksRemoved();
            current = s.substring("NoWeeks".length());
        } else if (current.startsWith("NoDays")) {
            periodType = periodType.withDaysRemoved();
            current = s.substring("NoDays".length());
        } else if (current.startsWith("NoHours")) {
            periodType = periodType.withHoursRemoved();
            current = s.substring("NoHours".length());
        } else if (current.startsWith("NoMinutes")) {
            periodType = periodType.withMinutesRemoved();
            current = s.substring("NoMinutes".length());
        } else if (current.startsWith("NoSeconds")) {
            periodType = periodType.withSecondsRemoved();
            current = s.substring("NoSeconds".length());
        } else if (current.startsWith("NoMillis")) {
            periodType = periodType.withMillisRemoved();
            current = s.substring("NoMillis".length());
        } else {
            throw new IllegalArgumentException("Unrecognised PeriodType: " + s + "{" + current + "}");
        }
    }
    return periodType;
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionImpl.java

License:Apache License

@Override
public String getTimeFancyText(DateTime from, DateTime to) {
    final String prefix = "Join in ";
    if (to != null) {
        Duration d = new Duration(to, from);
        Period timeUntil = new Period(to.toInstant(), from.toInstant(), PeriodType.dayTime());

        long standardDays = d.getStandardDays();

        if (standardDays > 0) {
            PeriodFormatter daysHours = new PeriodFormatterBuilder().appendDays().appendSuffix(" day", " days")
                    .appendSeparator(", and ").appendHours().appendSuffix(" hour", " hours").toFormatter();
            return prefix + daysHours.print(timeUntil.normalizedStandard(PeriodType.dayTime()));
        } else {//from  w  w  w .  j  ava 2 s .  com
            PeriodFormatter dafaultFormatter = new PeriodFormatterBuilder().appendHours()
                    .appendSuffix(" hour", " hours").appendSeparator(", and ").appendMinutes()
                    .appendSuffix(" minute", " minutes").toFormatter();
            return prefix + dafaultFormatter.print(timeUntil.normalizedStandard(PeriodType.dayTime()));
        }

    } else {
        return null;
    }
}

From source file:rapture.dp.invocable.purge.PurgeOldStorablesStep.java

License:Open Source License

private String getPrintableTtl(long ttl) {
    return PERIOD_FORMATTER.print(new Period(ttl).normalizedStandard(PeriodType.dayTime()));
}