1 package org.kuali.common.devops.vagrant.cloud.json;
2
3 import static java.util.TimeZone.getTimeZone;
4 import static org.kuali.common.util.base.Precondition.checkNotBlank;
5 import static org.kuali.common.util.base.Precondition.checkNotNull;
6
7 import java.text.SimpleDateFormat;
8 import java.util.TimeZone;
9
10 import org.apache.commons.lang3.builder.Builder;
11
12 public final class Timestamps {
13
14 private Timestamps() {
15 }
16
17 public static final String PRIVATE = "private";
18
19 private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
20 private static final TimeZone TIMESTAMP_TIMEZONE = getTimeZone("UTC");
21
22 public static Builder<SimpleDateFormat> newSimpleDateFormatBuilder() {
23 return new SimpleDateFormatBuilder(TIMESTAMP_FORMAT, TIMESTAMP_TIMEZONE);
24 }
25
26 private static class SimpleDateFormatBuilder implements Builder<SimpleDateFormat> {
27
28 public SimpleDateFormatBuilder(String format, TimeZone timezone) {
29 this.format = checkNotBlank(format, "format");
30 this.timezone = checkNotNull(timezone, "timezone");
31 }
32
33 private final String format;
34 private final TimeZone timezone;
35
36 @Override
37 public SimpleDateFormat build() {
38 SimpleDateFormat sdf = new SimpleDateFormat(format);
39 sdf.setTimeZone(timezone);
40 sdf.setLenient(false);
41 return sdf;
42 }
43
44 }
45
46 }