@js-joda/core

v6.0.0 BSD-3-Clause

a date and time library for javascript

Weekly Downloads
2.1M
Stars
1.7K
Forks
127
Open Issues
15
Gzip Size
41.4 kB
Unpacked Size
7.7 MB
Dependencies
1
Last Updated
2mo ago

@js-joda/core Download Trends

Download trends for @js-joda/core03.2M6.3M9.5M12.6MMar 2025JunSepDecMarApr 2026
@js-joda/core

About @js-joda/core

The @js-joda/core package provides a modern, immutable date and time API for JavaScript, designed to overcome the limitations of native JavaScript `Date` objects. It addresses common pain points such as mutability, time zone complexities, and the lack of comprehensive date manipulation functions, offering a more predictable and developer-friendly approach to handling temporal data. This library is built upon the principles of the highly regarded Joda-Time library from Java, bringing its robust design and features to the JavaScript ecosystem.

At its core, @js-joda/core emphasizes immutability, meaning that any operation performed on a date or time object returns a new instance rather than modifying the original. This design choice significantly reduces the risk of unintended side effects and makes date calculations easier to reason about, especially in concurrent environments or complex state management scenarios. The library targets developers who require precise and reliable date and time operations, moving beyond basic formatting and parsing to intricate temporal logic.

Key API patterns include fluent chaining of methods for complex operations, such as `LocalDate.now().plusDays(1).withDayOfMonth(15).format(DateTimeFormatter.ISO_LOCAL_DATE)`. It offers distinct classes for different temporal concepts: `LocalDate` for dates without time, `LocalTime` for times without dates, `LocalDateTime` for date-time combinations, and `ZonedDateTime` for date-time with time zone information. The library also provides extensive support for internationalization and time zone conversions using the IANA time zone database.

@js-joda/core integrates seamlessly into modern JavaScript build tools and frameworks. Its modular design allows for selective imports, helping to manage bundle size. Developers can utilize it within frameworks like React, Vue, or Angular, and it plays well with server-side rendering (SSR) and static site generation (SSG) workflows, ensuring consistent date and time handling across different environments. The package is well-suited for applications requiring accurate scheduling, event management, or historical data analysis.

The library's bundle size is approximately 41.4 kB (gzipped), which is a reasonable trade-off for its extensive functionality, especially considering its immutable nature and comprehensive feature set. While it introduces a dependency, the clarity and reliability it offers in date and time management often outweigh the inclusion of a new library. It is a mature solution, directly inspired by a proven Java API, providing a stable foundation for temporal logic.

Developers should be aware that the object-oriented API, while powerful, has a steeper learning curve compared to simpler date manipulation functions. The immutability, while beneficial, requires careful handling to avoid unnecessary object creation in performance-critical loops. For very basic tasks like simply displaying the current date or performing minimal arithmetic, lighter alternatives might exist, but for complex temporal requirements, @js-joda/core provides a robust and well-structured solution.

When to use

  • When performing complex date arithmetic, such as calculating business days, recurring events, or time differences across various time zones using `ZonedDateTime` and its numerous manipulation methods.
  • When needing to ensure that date and time objects are never modified after creation, thereby preventing bugs related to shared mutable state in applications, by leveraging the library’s immutable design for all temporal objects.
  • When working with internationalized applications that require precise handling of locales and time zone conversions, utilizing `ZoneId`, `ZoneOffset`, and `DateTimeFormatter` for accurate display and processing.
  • When building applications that rely on accurate historical data or future estimations, using classes like `Instant`, `Period`, and `Duration` to represent and compute specific points in time or intervals.
  • When migrating from Java applications that extensively use the Joda-Time library, providing a familiar and conceptually equivalent API in the JavaScript environment.
  • When needing to parse and format dates and times according to various standards or custom patterns, using `DateTimeFormatter` with predefined constants like `ISODateTimeFormatter.ISO_LOCAL_DATE` or custom pattern strings.

When NOT to use

  • If the application only requires basic date display or simple addition/subtraction, native JavaScript `Date` object methods or a more minimalist utility library might offer a smaller bundle size.
  • When the project has extremely strict performance requirements in tight loops where object instantiation is a critical bottleneck, consider simpler, mutable approaches if immutability is not a strict requirement.
  • If the domain logic exclusively involves parsing dates from a single, fixed format without complex manipulation or time zone considerations, a smaller, specialized parsing library could suffice.
  • When the primary need is for a simple timer or countdown mechanism without complex date-based logic, built-in browser APIs or simpler event listeners may be more appropriate.
  • If the development team is already heavily invested in a different date and time library and introducing another might lead to API confusion or increased maintenance overhead.

@js-joda/core Alternatives

@js-joda/core Categories