@opentripplanner/core-utils 4.9.0-alpha.1 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/time.js CHANGED
@@ -65,6 +65,22 @@ function formatDurationLikeMoment(
65
65
  }
66
66
  );
67
67
  }
68
+
69
+ /**
70
+ * Breaks up a duration in seconds into hours, minutes, and seconds.
71
+ * @param {number} seconds The number of seconds to break up
72
+ * @returns an object with fields with the corresponding, hours, minutes, seconds.
73
+ */
74
+ export function toHoursMinutesSeconds(seconds) {
75
+ const hours = Math.floor(seconds / 3600);
76
+ const minutes = Math.floor((seconds - hours * 3600) / 60);
77
+ return {
78
+ hours,
79
+ minutes,
80
+ seconds: seconds - hours * 3600 - minutes * 60
81
+ };
82
+ }
83
+
68
84
  /**
69
85
  * @param {[type]} config the OTP config object found in store
70
86
  * @return {string} the config-defined time formatter or HH:mm (24-hr time)
@@ -100,6 +116,15 @@ export function formatDuration(seconds) {
100
116
  export function formatDurationWithSeconds(seconds, region) {
101
117
  return formatDurationLikeMoment(seconds, { enabled: true, code: region });
102
118
  }
119
+
120
+ /**
121
+ * Offsets a time according to the provided time options
122
+ * and returns the result.
123
+ */
124
+ export function offsetTime(ms, options) {
125
+ return ms + (options?.offset || 0);
126
+ }
127
+
103
128
  /**
104
129
  * Formats a time value for display in narrative
105
130
  * TODO: internationalization/timezone
@@ -108,7 +133,7 @@ export function formatDurationWithSeconds(seconds, region) {
108
133
  */
109
134
  export function formatTime(ms, options) {
110
135
  return format(
111
- ms + (options?.offset || 0),
136
+ offsetTime(ms, options),
112
137
  options?.format || OTP_API_TIME_FORMAT
113
138
  );
114
139
  }