Skip to content

Commit

Permalink
[JENKINS-21267] Added method to obtain the remaining time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ialbors-pfc committed Feb 10, 2014
1 parent da03640 commit b5f5026
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
37 changes: 35 additions & 2 deletions src/main/java/hudson/plugins/nextexecutions/NextBuilds.java
Expand Up @@ -15,6 +15,13 @@

import net.sf.json.JSONObject;

import org.joda.time.DateTime;
import org.joda.time.Period;
import org.joda.time.PeriodType;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.DateTimeFormatterBuilder;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

Expand All @@ -30,13 +37,39 @@ public NextBuilds(AbstractProject project, Calendar date) {
this.date = date;
}

public String getDate() {
private String formatDate(Date d) {
String dateFormat = this.getDescriptor().getDateFormat();
if(dateFormat == null){
dateFormat = this.getDescriptor().getDefault();
}
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(date.getTime());
return sdf.format(d.getTime());
}

public String getDate() {
return formatDate(date.getTime());
}

public String getTimeToGo() {
DateTime now = new DateTime();

PeriodType periodType = PeriodType.dayTime();
periodType.withMillisRemoved();
Period timeToGo = new Period(now, new DateTime(date.getTimeInMillis()),
periodType);

PeriodFormatter pf = new PeriodFormatterBuilder().
appendDays().
appendSuffix("d").
appendSeparatorIfFieldsBefore(" ").
appendHours().
appendSuffix("h").
appendSeparatorIfFieldsBefore(" ").
appendMinutes().
appendSuffix("m").
toFormatter();

return Messages.TimeToGo(pf.print(timeToGo));
}

public String getName() {
Expand Down
@@ -1 +1,2 @@
Format.Error=The date format pattern is not valid.
Format.Error=The date format pattern is not valid.
TimeToGo=(in {0})

0 comments on commit b5f5026

Please sign in to comment.