未验证 提交 6d6129d6 编写于 作者: J Jesse Glick

[JENKINS-61806] Form validation for TimeZoneProperty.timeZoneName

上级 9eb0e58a
......@@ -6,6 +6,10 @@ import hudson.util.ListBoxModel.Option;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.Util;
import hudson.util.FormValidation;
import java.text.DateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.logging.Logger;
import java.util.logging.Level;
......@@ -13,6 +17,7 @@ import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.QueryParameter;
/**
......@@ -85,6 +90,18 @@ public class TimeZoneProperty extends UserProperty {
}
return items;
}
public FormValidation doCheckTimeZoneName(@QueryParameter String timeZoneName) {
Date now = new Date();
if (Util.fixEmpty(timeZoneName) == null) {
return FormValidation.ok(Messages.TimeZoneProperty_current_time_in_(TimeZone.getDefault().getDisplayName(), DateFormat.getDateTimeInstance().format(now)));
} else {
DateFormat localTime = DateFormat.getDateTimeInstance();
localTime.setTimeZone(TimeZone.getTimeZone(timeZoneName));
return FormValidation.ok(Messages.TimeZoneProperty_current_time_on_server_in_in_proposed_di(TimeZone.getDefault().getDisplayName(), DateFormat.getDateTimeInstance().format(now), localTime.format(now)));
}
}
}
@Nullable
......
......@@ -403,6 +403,8 @@ User.IllegalFullname="{0}" is prohibited as a full name for security reasons.
TimeZoneProperty.DisplayName=User Defined Time Zone
TimeZoneProperty.DisplayDefaultTimeZone=Default
TimeZoneProperty.current_time_in_=Current time in {0}: {1}
TimeZoneProperty.current_time_on_server_in_in_proposed_di=Current time on server in {0}: {1}; in proposed display zone: {2}
ManagementLink.Category.CONFIGURATION=System Configuration
ManagementLink.Category.SECURITY=Security
......
......@@ -18,4 +18,3 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
title=Time Zone
description=Specify user defined time zone for displaying time rather than system default.
<div>
Specify user defined time zone for displaying time rather than system default.
</div>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册