15
15
16
16
import net .sf .json .JSONObject ;
17
17
18
+ import org .joda .time .DateTime ;
19
+ import org .joda .time .Period ;
20
+ import org .joda .time .PeriodType ;
21
+ import org .joda .time .format .DateTimeFormatter ;
22
+ import org .joda .time .format .DateTimeFormatterBuilder ;
23
+ import org .joda .time .format .PeriodFormatter ;
24
+ import org .joda .time .format .PeriodFormatterBuilder ;
18
25
import org .kohsuke .stapler .QueryParameter ;
19
26
import org .kohsuke .stapler .StaplerRequest ;
20
27
28
+ /**
29
+ * Provides a way to get the project's next execution date.
30
+ *
31
+ */
21
32
public class NextBuilds implements Comparable , Describable <NextBuilds >{
22
33
private AbstractProject project ;
23
34
private String name ;
@@ -30,13 +41,39 @@ public NextBuilds(AbstractProject project, Calendar date) {
30
41
this .date = date ;
31
42
}
32
43
33
- public String getDate ( ) {
44
+ private String formatDate ( Date d ) {
34
45
String dateFormat = this .getDescriptor ().getDateFormat ();
35
46
if (dateFormat == null ){
36
47
dateFormat = this .getDescriptor ().getDefault ();
37
48
}
38
49
SimpleDateFormat sdf = new SimpleDateFormat (dateFormat );
39
- return sdf .format (date .getTime ());
50
+ return sdf .format (d .getTime ());
51
+ }
52
+
53
+ public String getDate () {
54
+ return formatDate (date .getTime ());
55
+ }
56
+
57
+ public String getTimeToGo () {
58
+ DateTime now = new DateTime ();
59
+
60
+ PeriodType periodType = PeriodType .dayTime ();
61
+ periodType .withMillisRemoved ();
62
+ Period timeToGo = new Period (now , new DateTime (date .getTimeInMillis ()),
63
+ periodType );
64
+
65
+ PeriodFormatter pf = new PeriodFormatterBuilder ().
66
+ appendDays ().
67
+ appendSuffix ("d" ).
68
+ appendSeparatorIfFieldsBefore (" " ).
69
+ appendHours ().
70
+ appendSuffix ("h" ).
71
+ appendSeparatorIfFieldsBefore (" " ).
72
+ appendMinutes ().
73
+ appendSuffix ("m" ).
74
+ toFormatter ();
75
+
76
+ return Messages .TimeToGo (pf .print (timeToGo ));
40
77
}
41
78
42
79
public String getName () {
0 commit comments