summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/date-time.js44
-rw-r--r--src/util/date-time.test.js35
-rw-r--r--src/util/jquery.js6
3 files changed, 56 insertions, 29 deletions
diff --git a/src/util/date-time.js b/src/util/date-time.js
index 26039368..e9d7664f 100644
--- a/src/util/date-time.js
+++ b/src/util/date-time.js
@@ -45,7 +45,7 @@ export function parseDateTime(dateTimeString) {
/**
* Serializes the given date and time value to a human-friendly string.
*
- * @param dateTime An rack representation of a date and time.
+ * @param dateTime An object representation of a date and time.
* @returns {string} A human-friendly string version of that date and time.
*/
export function formatDateTime(dateTime) {
@@ -71,34 +71,6 @@ export function formatDateTime(dateTime) {
}
/**
- * Returns a string representation of the current date and time.
- *
- * The format assumed is "YYYY-MM-DDTHH:MM:SS".
- *
- * @returns {string} A string representation of the current date and time.
- */
-export function getCurrentDateTime() {
- const currentDate = new Date();
- return currentDate.getFullYear() + "-" + addPaddingToTwo(currentDate.getMonth() + 1) + "-" +
- addPaddingToTwo(currentDate.getDate()) + "T" + addPaddingToTwo(currentDate.getHours()) + ":" +
- addPaddingToTwo(currentDate.getMinutes()) + ":" + addPaddingToTwo(currentDate.getSeconds());
-}
-
-/**
- * Pads the given integer to have at least two digits.
- *
- * @param integer An integer to be padded.
- * @returns {string} A string containing the padded integer.
- */
-export function addPaddingToTwo(integer) {
- if (integer < 10) {
- return "0" + integer.toString();
- } else {
- return integer.toString();
- }
-}
-
-/**
* Formats the given number of seconds/ticks to a formatted time representation.
*
* @param seconds The number of seconds.
@@ -125,3 +97,17 @@ export function convertSecondsToFormattedTime(seconds) {
return hour + "h" + addPaddingToTwo(minute) + "m" + addPaddingToTwo(second) + "s";
}
}
+
+/**
+ * Pads the given integer to have at least two digits.
+ *
+ * @param integer An integer to be padded.
+ * @returns {string} A string containing the padded integer.
+ */
+function addPaddingToTwo(integer) {
+ if (integer < 10) {
+ return "0" + integer.toString();
+ } else {
+ return integer.toString();
+ }
+}
diff --git a/src/util/date-time.test.js b/src/util/date-time.test.js
new file mode 100644
index 00000000..9dce202b
--- /dev/null
+++ b/src/util/date-time.test.js
@@ -0,0 +1,35 @@
+import {convertSecondsToFormattedTime, parseDateTime} from "./date-time";
+
+describe("date-time parsing", () => {
+ it("reads components properly", () => {
+ const dateString = "2017-09-27T20:55:01";
+ const parsedDate = parseDateTime(dateString);
+
+ expect(parsedDate.year).toEqual(2017);
+ expect(parsedDate.month).toEqual(9);
+ expect(parsedDate.day).toEqual(27);
+ expect(parsedDate.hour).toEqual(20);
+ expect(parsedDate.minute).toEqual(55);
+ expect(parsedDate.second).toEqual(1);
+ });
+});
+
+describe("tick formatting", () => {
+ it("returns '0s' for numbers <= 0", () => {
+ expect(convertSecondsToFormattedTime(-1)).toEqual("0s");
+ expect(convertSecondsToFormattedTime(0)).toEqual("0s");
+ });
+ it("returns only seconds for values under a minute", () => {
+ expect(convertSecondsToFormattedTime(1)).toEqual("1s");
+ expect(convertSecondsToFormattedTime(59)).toEqual("59s");
+ });
+ it("returns seconds and minutes for values under an hour", () => {
+ expect(convertSecondsToFormattedTime(60)).toEqual("1m00s");
+ expect(convertSecondsToFormattedTime(61)).toEqual("1m01s");
+ expect(convertSecondsToFormattedTime(3599)).toEqual("59m59s");
+ });
+ it("returns full time for values over an hour", () => {
+ expect(convertSecondsToFormattedTime(3600)).toEqual("1h00m00s");
+ expect(convertSecondsToFormattedTime(3601)).toEqual("1h00m01s");
+ });
+});
diff --git a/src/util/jquery.js b/src/util/jquery.js
index dd0a7222..12a64fc6 100644
--- a/src/util/jquery.js
+++ b/src/util/jquery.js
@@ -1,2 +1,8 @@
+/**
+ * Binding of the global jQuery variable for use within React.
+ *
+ * This should be used instead of '$', to address ESLint warnings relating to undefined global variables.
+ */
const jQuery = window["$"];
+
export default jQuery;