-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66e2f25
commit 1a9018c
Showing
3 changed files
with
93 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.structurizr.cli.util; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* Utilities for calculating various points in time. | ||
*/ | ||
public class DateUtils { | ||
|
||
public static final String UTC_TIME_ZONE = "UTC"; | ||
public static final String ISO_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; | ||
|
||
public static Calendar getCalendar() { | ||
return Calendar.getInstance(TimeZone.getTimeZone(UTC_TIME_ZONE)); | ||
} | ||
|
||
public static Date getNow() { | ||
return getCalendar().getTime(); | ||
} | ||
|
||
public static Date removeMilliseconds(Date date) { | ||
Calendar cal = getCalendar(); | ||
cal.setTime(date); | ||
cal.set(Calendar.MILLISECOND, 0); | ||
|
||
return cal.getTime(); | ||
} | ||
|
||
public static String formatIsoDate(Date d) { | ||
if (d != null) { | ||
SimpleDateFormat sdf = new SimpleDateFormat(ISO_DATE_TIME_FORMAT); | ||
sdf.setTimeZone(TimeZone.getTimeZone(UTC_TIME_ZONE)); | ||
|
||
return sdf.format(d); | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.structurizr.cli.util; | ||
|
||
import java.io.InputStream; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Properties; | ||
|
||
public class Version { | ||
|
||
private static final String BUILD_VERSION_KEY = "build.number"; | ||
private static final String BUILD_TIMESTAMP_KEY = "build.timestamp"; | ||
private static final String GIT_COMMIT_KEY = "git.commit"; | ||
|
||
private static String version = ""; | ||
private static Date buildTimestamp = new Date(); | ||
private static String gitCommit; | ||
|
||
static { | ||
try { | ||
Properties buildProperties = new Properties(); | ||
InputStream in = Version.class.getClassLoader().getResourceAsStream("build.properties"); | ||
DateFormat format = new SimpleDateFormat(DateUtils.ISO_DATE_TIME_FORMAT); | ||
if (in != null) { | ||
buildProperties.load(in); | ||
version = buildProperties.getProperty(BUILD_VERSION_KEY); | ||
buildTimestamp = format.parse(buildProperties.getProperty(BUILD_TIMESTAMP_KEY)); | ||
gitCommit = buildProperties.getProperty(GIT_COMMIT_KEY); | ||
in.close(); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public String getBuildNumber() { | ||
return version; | ||
} | ||
|
||
public Date getBuildTimestamp() { | ||
return buildTimestamp; | ||
} | ||
|
||
public String getGitCommit() { | ||
return gitCommit; | ||
} | ||
|
||
} |