提交 802af115 编写于 作者: K kohsuke

added an object to represent the clock difference.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3919 71c3de6d-444a-0410-be80-ed276b4c234a
上级 1a0a55b4
package hudson.util;
import hudson.Util;
/**
* Represents a clock difference. Immutable.
*
* @author Kohsuke Kawaguchi
*/
public final class ClockDifference {
/**
* The difference in milliseconds.
*
* Positive value means the slave is behind the master,
* negative value means the slave is ahead of the master.
*/
public final Long diff;
public ClockDifference(long value) {
this.diff = value;
}
/**
* Returns true if the difference is big enough to be considered dangerous.
*/
public boolean isDangerous() {
return Math.abs(diff)>5000;
}
/**
* Gets the clock difference in HTML string.
*/
public String toString() {
if(-1000<diff && diff <1000)
return "In sync"; // clock is in sync
long abs = Math.abs(diff);
String s = Util.getTimeSpanString(abs);
if(diff<0)
s += " ahead";
else
s += " behind";
return s;
}
public String toHtml() {
String s = toString();
if(isDangerous()) s = "<span class=error>"+s+"</span>";
return s;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册