Example usage for org.joda.time Duration plus

List of usage examples for org.joda.time Duration plus

Introduction

In this page you can find the example usage for org.joda.time Duration plus.

Prototype

public Duration plus(ReadableDuration amount) 

Source Link

Document

Returns a new duration with this length plus that specified.

Usage

From source file:com.kopysoft.chronos.adapter.clock.PayPeriodAdapterList.java

License:Open Source License

public static Duration getTime(List<PunchPair> punches, boolean allowNegative) {
    Duration dur = new Duration(0);

    for (PunchPair pp : punches) {
        if (enableLog)
            Log.d(TAG, "Punch Size: " + pp.getDuration());
        if (!pp.getInPunch().getTask().getEnablePayOverride())
            dur = dur.plus(pp.getDuration());
        else if (pp.getInPunch().getTask().getPayOverride() > 0)
            dur = dur.plus(pp.getDuration());
        else/*from   w  w w .j  ava  2  s . c o m*/
            dur = dur.minus(pp.getDuration());
    }

    if (dur.getMillis() < 0 && !allowNegative)
        dur = new Duration(0);

    return dur;
}

From source file:com.kopysoft.chronos.adapter.clock.TodayAdapterPair.java

License:Open Source License

public static Duration getTime(List<PunchPair> punches, boolean allowNegative) {
    Duration dur = new Duration(0);

    for (PunchPair pp : punches) {
        if (enableLog)
            Log.d(TAG, "Punch Size: " + pp.getDuration());
        if (!pp.getInPunch().getTask().getEnablePayOverride())
            dur = dur.plus(pp.getDuration());
        else if (pp.getTask().getPayOverride() == 0)
            continue;
        else if (pp.getInPunch().getTask().getPayOverride() > 0)
            dur = dur.plus(pp.getDuration());
        else/*  w w w. j  a  v a2s .com*/
            dur = dur.minus(pp.getDuration());
    }

    if (dur.getMillis() < 0 && !allowNegative)
        dur = new Duration(0);

    return dur;
}

From source file:com.kopysoft.chronos.lib.Email.java

License:Open Source License

public String getBriefView() {
    String retString = "";
    List<DateTime> dates = punchTable.getDays();
    Chronos chron = new Chronos(gContext);
    Duration totalDuration = new Duration(0);

    for (DateTime date : dates) {
        DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy");
        String time = fmt.print(date);

        Duration dur = PayPeriodAdapterList.getTime(punchTable.getPunchPair(date));
        retString += time/*  w w w  .  j a v a 2 s.co  m*/
                + String.format(" - %02d:%02d\n", dur.toPeriod().getHours(), dur.toPeriod().getMinutes());

        totalDuration = totalDuration.plus(dur);
        Note note = chron.getNoteByDay(date);

        if (!note.getNote().equalsIgnoreCase("")) {
            retString += "\tNote: " + note.getNote() + "\n";
        }
    }

    retString += String.format("Total time - %02d:%02d\n", totalDuration.getStandardHours(),
            totalDuration.getStandardMinutes() % 60);

    chron.close();
    return retString;
}

From source file:com.kopysoft.chronos.lib.Email.java

License:Open Source License

public String getExpandedView() {
    String retString = "";
    List<DateTime> dates = punchTable.getDays();

    DateTimeFormatter dateFormat = DateTimeFormat.forPattern("E, MMM d, yyyy:\n");
    DateTimeFormatter fmt;/*from w  ww . j av a  2 s . c om*/
    if (!DateFormat.is24HourFormat(gContext))
        fmt = DateTimeFormat.forPattern("h:mm a");
    else
        fmt = DateTimeFormat.forPattern("HH:mm");

    Chronos chron = new Chronos(gContext);
    Duration totalDuration = new Duration(0);

    for (DateTime date : dates) {
        if (punchTable.getPunchPair(date).size() > 0)
            retString += dateFormat.print(date);

        for (PunchPair pp : punchTable.getPunchPair(date)) {
            retString += "\t" + fmt.print(pp.getInPunch().getTime()) + " - \tIN - "
                    + pp.getInPunch().getTask().getName() + "\n";
            if (pp.getOutPunch() != null) {
                retString += "\t" + fmt.print(pp.getOutPunch().getTime()) + " - \tOUT - "
                        + pp.getOutPunch().getTask().getName() + "\n";
            }
        }

        totalDuration = totalDuration.plus(PayPeriodAdapterList.getTime(punchTable.getPunchPair(date)));

        Note note = chron.getNoteByDay(date);

        if (!note.getNote().equalsIgnoreCase("")) {
            retString += "\tNote: " + note.getNote() + "\n";
        }
    }

    retString += String.format("Total time - %02d:%02d\n", totalDuration.getStandardHours(),
            totalDuration.getStandardMinutes() % 60);

    chron.close();
    return retString;
}

From source file:com.kopysoft.chronos.views.ClockFragments.Today.DatePairView.java

License:Open Source License

private void createUI(TodayAdapterPair adpter, Job thisJob) {

    //if(enableLog) Log.d(TAG, "Position: " + position);
    setOrientation(LinearLayout.VERTICAL);

    //retView.setOnItemLongClickListener(LongClickListener);

    header = View.inflate(getContext(), R.layout.today_view, null);

    DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy");
    ((TextView) header.findViewById(R.id.date)).setText(fmt.print(gDate));

    if (!showPay()) {
        header.findViewById(R.id.moneyViewText).setVisibility(View.GONE);
        header.findViewById(R.id.moneyViewTotal).setVisibility(View.GONE);
    }//from   w  w  w .  java 2 s. c  o m

    ListView retView = (ListView) header.findViewById(R.id.listView);
    retView.setOnItemClickListener(listener);

    TextView tx = (TextView) header.findViewById(R.id.timeViewTotal);
    Duration dur = adapter.getTime(true);

    if (dur.getMillis() < 0 && gDate.toDateMidnight().isEqual(new DateMidnight())) {
        dur = dur.plus(DateTime.now().getMillis());
    }

    int seconds = (int) dur.getStandardSeconds();
    int minutes = (seconds / 60) % 60;
    int hours = (seconds / 60 / 60);
    String output = String.format("%d:%02d:%02d", hours, minutes, seconds % 60);

    if (dur.getMillis() >= 0)
        tx.setText(output);
    else
        tx.setText("--:--:--");

    if (enableLog)
        Log.d(TAG, "job: " + thisJob);
    if (enableLog)
        Log.d(TAG, "seconds: " + seconds);
    if (enableLog)
        Log.d(TAG, "dur: " + dur.toString());
    if (enableLog)
        Log.d(TAG, "pay rate: " + thisJob.getPayRate());

    double money = adapter.getPayableTime(gDate.toDateMidnight().isEqual(new DateMidnight()));

    Currency moneyCurrency = Currency.getInstance(Locale.getDefault());
    output = String.format("%s %.2f", moneyCurrency.getSymbol(), money);
    tx = (TextView) header.findViewById(R.id.moneyViewTotal);
    tx.setText(output);
    if (enableLog)
        Log.d(TAG, "pay amount: " + output);

    //header to the row
    addView(header);

    retView.setAdapter(adpter);
    retView.setSelection(0);

    //show button
    if (!gDate.toDateMidnight().isEqual(new DateMidnight())) {
        header.findViewById(R.id.clockInAndOutButton).setVisibility(View.GONE);
    } else {
        (header.findViewById(R.id.clockInAndOutButton)).setOnClickListener(buttonListener);
        if (dur.getMillis() < 0) {
            ((Button) header.findViewById(R.id.clockInAndOutButton)).setText("Clock Out");
        } else {
            ((Button) header.findViewById(R.id.clockInAndOutButton)).setText("Clock In");
        }
    }

}

From source file:com.kopysoft.chronos.views.ClockFragments.Today.DatePairView.java

License:Open Source License

private void updateTime() {
    TextView tx = (TextView) header.findViewById(R.id.timeViewTotal);
    Duration dur = adapter.getTime(true);
    if (dur.getMillis() < 0 && gDate.toDateMidnight().isEqual(new DateMidnight())) {
        dur = dur.plus(DateTime.now().getMillis());
    }//from ww w  .  ja  va 2  s  . c om

    int seconds = (int) dur.getStandardSeconds();
    int minutes = (seconds / 60) % 60;
    int hours = (seconds / 60 / 60);
    String output = String.format("%d:%02d:%02d", hours, minutes, seconds % 60);
    tx.setText(output);

    double money = adapter.getPayableTime(true);

    Currency moneyCurrency = Currency.getInstance(Locale.getDefault());
    output = String.format("%s %.2f", moneyCurrency.getSymbol(), money);

    tx = (TextView) header.findViewById(R.id.moneyViewTotal);
    tx.setText(output);
    if (enableLog)
        Log.d(TAG, "pay amount: " + output);
}

From source file:com.metamx.druid.BaseQuery.java

License:Open Source License

@Override
public Duration getDuration() {
    if (duration == null) {
        Duration totalDuration = new Duration(0);
        for (Interval interval : querySegmentSpec.getIntervals()) {
            if (interval != null) {
                totalDuration = totalDuration.plus(interval.toDuration());
            }//www .  j  a v a 2 s  .  co m
        }
        duration = totalDuration;
    }

    return duration;
}

From source file:com.moosemorals.movieeditor.Splitter.java

License:Open Source License

public static void split(Config config, List<TimingPair> pairs) throws IOException {
    File temp = File.createTempFile("scratch", "tmp");

    File finalResult = new File(config.getOutputFile());

    if (finalResult.exists()) {
        finalResult.delete();/*from  ww w .j a  v a  2 s .  com*/
    }

    Duration length = Duration.ZERO;

    try (PrintWriter out = new PrintWriter(new FileWriter(temp))) {
        for (TimingPair pair : pairs) {
            File partFile = File.createTempFile("part-", ".ts", config.getTempDir());
            partFile.deleteOnExit();

            String[] cmd = { "/usr/bin/ffmpeg", "-hide_banner", "-progress",
                    buildTargetURI(config, "start", TimingPair.format(pair.getStart()), "duration",
                            TimingPair.format(pair.getDuration())),
                    "-loglevel", "0", "-y", "-ss", TimingPair.format(pair.getStart()), "-t",
                    TimingPair.format(pair.getDuration()), "-i", config.getInputFile(), "-f", "mpegts", "-c",
                    "copy", "-avoid_negative_ts", "1", "-copyts", partFile.getAbsolutePath() };

            int result = runProcess(cmd);
            log.info("Process result {}", result);
            if (result != 0) {
                throw new IOException("ffmpeg error, no details. Sorry.");
            }
            out.printf("file '%s'\n", partFile.getAbsolutePath());

            length = length.plus(pair.getDuration());
        }
        out.flush();
    }

    String[] cmd = { "/usr/bin/ffmpeg", "-hide_banner", "-progress",
            buildTargetURI(config, "start", TimingPair.format(Duration.ZERO), "duration",
                    TimingPair.format(length)),
            "-loglevel", "0", "-f", "concat", "-safe", "0", "-i", temp.getAbsolutePath(), "-c", "copy",
            finalResult.getAbsolutePath() };

    int result = runProcess(cmd);
    log.debug("Process result {}", result);
}

From source file:is.illuminati.block.spyros.garmin.model.Activity.java

License:Open Source License

/**
 * Get net duration (from start time to time of last measurement, minus
 * pauses) of the {@link Activity}./* w w w.j  a  v a 2 s .  co  m*/
 * @return net duration
 */
public Duration getNetDuration() {
    // start with the difference between start time and first lap start time.
    Duration netDuration = new Duration(startTime, laps.get(0).getStartTime());
    for (Lap lap : laps) {
        netDuration = netDuration.plus(lap.getNetDuration());
    }
    return netDuration;
}

From source file:is.illuminati.block.spyros.garmin.model.Lap.java

License:Open Source License

/**
 * Get net duration of Lap. That is, the time from start to end, minus the
 * pauses./*ww w.  ja  v  a 2 s.  com*/
 * @return net duration of lap.
 */
public Duration getNetDuration() {
    Duration duration = new Duration(startTime, tracks.get(0).getStartTime());
    for (Track track : tracks) {
        duration = duration.plus(track.getDuration());
    }
    return duration;
}