@openzeppelin/ui-utils 1.2.1 → 1.2.2

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/dist/index.cjs CHANGED
@@ -1156,6 +1156,25 @@ function formatTimestamp(date) {
1156
1156
  return date.toLocaleDateString();
1157
1157
  }
1158
1158
  /**
1159
+ * Formats seconds into a human-readable duration string (e.g. "1 day", "24 hours", "30 minutes").
1160
+ * @param seconds Duration in seconds
1161
+ * @returns Human-readable string with correct singular/plural
1162
+ */
1163
+ function formatSecondsToReadable(seconds) {
1164
+ if (seconds <= 0 || !Number.isFinite(seconds)) return "0 seconds";
1165
+ if (seconds < 60) return seconds === 1 ? "1 second" : `${seconds} seconds`;
1166
+ if (seconds < 3600) {
1167
+ const mins = Math.floor(seconds / 60);
1168
+ return mins === 1 ? "1 minute" : `${mins} minutes`;
1169
+ }
1170
+ if (seconds < 86400) {
1171
+ const hours = Math.floor(seconds / 3600);
1172
+ return hours === 1 ? "1 hour" : `${hours} hours`;
1173
+ }
1174
+ const days = Math.floor(seconds / 86400);
1175
+ return days === 1 ? "1 day" : `${days} days`;
1176
+ }
1177
+ /**
1159
1178
  * Detects whether a string contains hex-encoded or base64-encoded binary data.
1160
1179
  * Useful for auto-detecting the encoding format of user inputs across blockchain adapters.
1161
1180
  *
@@ -2476,6 +2495,7 @@ exports.detectServiceType = detectServiceType;
2476
2495
  exports.enhanceNumericValidation = enhanceNumericValidation;
2477
2496
  exports.findRoleAssignment = findRoleAssignment;
2478
2497
  exports.formatAccessControlError = formatAccessControlError;
2498
+ exports.formatSecondsToReadable = formatSecondsToReadable;
2479
2499
  exports.formatTimestamp = formatTimestamp;
2480
2500
  exports.generateId = generateId;
2481
2501
  exports.getAllMembers = getAllMembers;