Extra Time Information
getUTCOffset()β
Signatureβ
getUTCOffset(): string
Return Typeβ
string
β Offset string in the format Β±HH:mm
(e.g., +05:30
, -06:00
)
Descriptionβ
Returns the systemβs current UTC offset in string format.
Unlike JavaScript's Date.prototype.getTimezoneOffset()
which returns the offset in minutes behind UTC (positive for locations west of UTC), this method returns a human-readable offset using time zone sign conventions (e.g., +06:00
means 6 hours ahead of UTC).
Exampleβ
new Chronos('2025-01-15').getUTCOffset(); // "-05:00" for EST
getTimeZoneOffset()β
Signatureβ
getTimeZoneOffset(): string
Return Typeβ
string
β Offset string in the format Β±HH:mm
Descriptionβ
Returns the offset string of this Chronos instanceβs stored timezone, regardless of the current system's timezone.
- Useful for working with date instances that were parsed with or set to a specific timezone.
Follows the same sign convention as getUTCOffset()
β positive if ahead of UTC, negative if behind.
Exampleβ
new Chronos().timeZone('IST-IN').getTimeZoneOffset(); // "+05:30"
getUTCOffsetMinutes()β
Signatureβ
getUTCOffsetMinutes(): number
Return Typeβ
number
β The offset in minutes
Descriptionβ
Returns the systemβs UTC offset in minutes, but using a flipped sign convention from JavaScript's native API:
- Returns a positive value if the local time is ahead of UTC.
- Returns a negative value if behind UTC.
π§ This matches the intuitive reading of +06:00 β 360
, -05:30 β -330
, unlike Date.prototype.getTimezoneOffset()
which reverses this.
Exampleβ
new Chronos().getUTCOffsetMinutes(); // 360 for UTC+06:00
getTimeZoneOffsetMinutes()β
Signatureβ
getTimeZoneOffsetMinutes(): number
Return Typeβ
number
β The offset in minutes
Descriptionβ
Returns the offset of the current Chronos instance's timezone in minutes, based on the internally stored offset string (e.g., UTC+06:00
β 360
).
- Independent of system timezone
- Matches the
Β±HH:mm
sign convention
Used internally for calculating UTC equivalence, especially when converting between time zones.
Exampleβ
new Chronos().timeZone('IST-IN').getTimeZoneOffsetMinutes(); // 330
toAcademicYear()β
This method is provided by businessPlugin
. You must register it using Chronos.use(businessPlugin)
before calling .toAcademicYear()
. Once registered, all Chronos instances will have access to the .toAcademicYear()
method.
Signatureβ
toAcademicYear(): `${number}-${number}`
Return Typeβ
string
- Academic year string
Notesβ
- Assumes academic year runs July-June
Exampleβ
import { Chronos } from 'nhb-toolbox';
import { businessPlugin } from 'nhb-toolbox/plugins/businessPlugin';
Chronos.use(businessPlugin);
new Chronos('2025-01-15').toAcademicYear(); // "2022-2025"
new Chronos('2025-08-15').toAcademicYear(); // "2025-2024"
toQuarter()β
Signatureβ
toQuarter(): Quarter
Return Typeβ
Quarter
- Calendar quarter (1-4)
Notesβ
- Q1: Jan-Mar, Q2: Apr-Jun, Q3: Jul-Sep, Q4: Oct-Dec
Exampleβ
new Chronos('2025-01-15').toQuarter(); // 1
new Chronos('2025-04-01').toQuarter(); // 2
toFiscalQuarter()β
This method is provided by businessPlugin
. You must register it using Chronos.use(businessPlugin)
before calling .toFiscalQuarter()
. Once registered, all Chronos instances will have access to the .toFiscalQuarter()
method.
Signatureβ
toFiscalQuarter(startMonth?: NumberRange<1, 12>): Quarter
Parametersβ
startMonth
: Fiscal year start month (1-12, default: 7)
Return Typeβ
Quarter
- Fiscal quarter (1-4)
Notesβ
- Default assumes fiscal year starts in July
Exampleβ
import { Chronos } from 'nhb-toolbox';
import { businessPlugin } from 'nhb-toolbox/plugins/businessPlugin';
Chronos.use(businessPlugin);
new Chronos('2025-01-15').toFiscalQuarter(); // 3 (July-start year)
new Chronos('2025-01-15').toFiscalQuarter(10); // 2 (October-start year)