@herowcode/utils 1.1.9 → 1.1.10

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/README.md CHANGED
@@ -118,6 +118,17 @@ Converts a Date to a Dayjs object in UTC.
118
118
  getDateInUTC(new Date());
119
119
  ```
120
120
 
121
+ #### `getRelativeTime(date: ConfigType, dateNow?: Dayjs | ConfigType): string`
122
+ Returns a human-readable relative time string (for example: "a few seconds ago", "in 2 days"). It accepts any input supported by dayjs (Date, string, number) and an optional `dateNow` parameter to compute the difference against a custom reference time.
123
+
124
+ ```typescript
125
+ // Using a fixed reference
126
+ getRelativeTime('2025-09-15T11:59:00Z', dayjs('2025-09-15T12:00:00Z')) // "a minute ago"
127
+
128
+ // Or with default reference (now)
129
+ getRelativeTime(new Date()) // "a few seconds ago"
130
+ ```
131
+
121
132
  #### `parseTimeSpent(initialDate: string | Date, finalDate: string | Date, locale?: string, options?: { format?: 'verbose' | 'compact'; minimal?: boolean }): ITimeSpent`
122
133
 
123
134
  Retorna um objeto com a decomposição do tempo entre duas datas e uma string formatada. Estrutura retornada (ITimeSpent):
@@ -0,0 +1,3 @@
1
+ import type { ConfigType } from "dayjs";
2
+ export declare function getRelativeTime(date: ConfigType, dateNow?: import("dayjs").Dayjs): string;
3
+ //# sourceMappingURL=get-relative-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-relative-time.d.ts","sourceRoot":"","sources":["../../../src/date/get-relative-time.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGvC,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,wBAAU,GAAG,MAAM,CAE3E"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRelativeTime = getRelativeTime;
4
+ const dayjs_1 = require("./dayjs");
5
+ function getRelativeTime(date, dateNow = (0, dayjs_1.dayjs)()) {
6
+ return (0, dayjs_1.dayjs)(date).from(dateNow);
7
+ }
8
+ //# sourceMappingURL=get-relative-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-relative-time.js","sourceRoot":"","sources":["../../../src/date/get-relative-time.ts"],"names":[],"mappings":";;AAGA,0CAEC;AAJD,mCAA+B;AAE/B,SAAgB,eAAe,CAAC,IAAgB,EAAE,OAAO,GAAG,IAAA,aAAK,GAAE;IACjE,OAAO,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAClC,CAAC"}
@@ -3,5 +3,6 @@ export * from "./fix-timezone-offset";
3
3
  export * from "./format-date";
4
4
  export * from "./get-current-date-in-utc";
5
5
  export * from "./get-date-in-utc";
6
+ export * from "./get-relative-time";
6
7
  export * from "./parse-time-spent";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
@@ -19,5 +19,6 @@ __exportStar(require("./fix-timezone-offset"), exports);
19
19
  __exportStar(require("./format-date"), exports);
20
20
  __exportStar(require("./get-current-date-in-utc"), exports);
21
21
  __exportStar(require("./get-date-in-utc"), exports);
22
+ __exportStar(require("./get-relative-time"), exports);
22
23
  __exportStar(require("./parse-time-spent"), exports);
23
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,wDAAqC;AACrC,gDAA6B;AAC7B,4DAAyC;AACzC,oDAAiC;AACjC,qDAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,wDAAqC;AACrC,gDAA6B;AAC7B,4DAAyC;AACzC,oDAAiC;AACjC,sDAAmC;AACnC,qDAAkC"}
@@ -0,0 +1,3 @@
1
+ import type { ConfigType } from "dayjs";
2
+ export declare function getRelativeTime(date: ConfigType, dateNow?: import("dayjs").Dayjs): string;
3
+ //# sourceMappingURL=get-relative-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-relative-time.d.ts","sourceRoot":"","sources":["../../src/date/get-relative-time.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGvC,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,wBAAU,GAAG,MAAM,CAE3E"}
@@ -3,5 +3,6 @@ export * from "./fix-timezone-offset";
3
3
  export * from "./format-date";
4
4
  export * from "./get-current-date-in-utc";
5
5
  export * from "./get-date-in-utc";
6
+ export * from "./get-relative-time";
6
7
  export * from "./parse-time-spent";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { dayjs } from "./dayjs.js";
2
+ export function getRelativeTime(date, dateNow = dayjs()) {
3
+ return dayjs(date).from(dateNow);
4
+ }
@@ -3,4 +3,5 @@ export * from "./fix-timezone-offset.js";
3
3
  export * from "./format-date.js";
4
4
  export * from "./get-current-date-in-utc.js";
5
5
  export * from "./get-date-in-utc.js";
6
+ export * from "./get-relative-time.js";
6
7
  export * from "./parse-time-spent.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herowcode/utils",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "A lightweight collection of utility functions for everyday JavaScript/TypeScript development",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",