Module java_time_utils

kruutteri1/java_time_utils

1.1.5

Overview

A Ballerina wrapper around java.timeLocalDate, LocalDateTime, LocalTime, ZonedDateTime, OffsetDateTime, Instant, ZoneId, ZoneOffset, ZoneRules, and other core helper and enum classes like Month, FormatStyle and DayOfWeek for working with dates, times, time zones, and temporal components.

java.time is the gold standard for date and time handling on the JVM. java_time_utils brings that same power into Ballerina — precise date/time arithmetic, instant tracking, zone-aware operations, immutable values, and predictable behavior, all in one library, whether or not your use case involves time zones.

Installation

Copy
# Ballerina.toml
[[dependency]]
org = "kruutteri1"
name = "java_time_utils"
version = "1.1.5"  # ⚠️ check central.ballerina.io for the latest version
Copy
import kruutteri1/java_time_utils as jt;

Quick Start

Copy
import ballerina/io;
import kruutteri1/java_time_utils as jt;

public function main() returns error? {
    jt:LocalDate date = check jt:ofDate(2026, 7, 15);
    jt:LocalTime time = check jt:ofTimeWithSecond(14, 28, 19);
    jt:LocalDateTime dateTime = check jt:ofLocalDateWithLocalTime(date, time);

    io:println(date.toString());      // 2026-07-15
    io:println(time.toString());      // 14:28:19
    io:println(dateTime.toString());  // 2026-07-15T14:28:19
}

Getting the Current Date and Time Without Zone

Copy
import ballerina/io;
import kruutteri1/java_time_utils as jt;

public function main() {
    jt:LocalDate today = jt:getCurrentDate();
    jt:LocalTime now = jt:getCurrentTime();
    jt:LocalDateTime currentDateTime = jt:getCurrentDateTime();

    io:println("Today: ", today.toString());             // Today: 2026-07-22
    io:println("Now: ", now.toString());                 // Now: 14:57:30
    io:println("Current date-time: ", currentDateTime.toString()); // Current date-time: 2026-07-22T14:57:30
}

Features

  • 📅 LocalDate — dates without time or time zone
  • 🗓️ LocalDateTime — dates with time, no time zone
  • 🕒 LocalTime — time of day without date or time zone
  • Duration — time-based amount of time (e.g., seconds, nanoseconds)
  • Period — date-based amount of time (e.g., years, months, days)
  • 📅 Month — month-of-year enum representation (such as January, July)
  • 📅 DayOfWeek — day-of-week enum representation (such as Monday, Sunday)
  • 🕒 DateTimeFormatter — formatting and parsing for temporal objects
  • ⏱️ Instant — specific point on the time-line, measured in seconds and nanoseconds from the Unix epoch
  • 🌍 ZonedDateTime — date-time with a full time-zone (region + offset), zone-aware arithmetic and conversions
  • 🕐 OffsetDateTime — date-time with a fixed offset from UTC (no region rules), such as "2026-07-31T14:28:19+02:00"
  • 🌐 ZoneId — time-zone identifiers (such as "Europe/Kyiv"), including system default and legacy short IDs
  • ➕➖ ZoneOffset — fixed offset from UTC (such as "+02:00"), with dedicated UTC, MIN, and MAX constants
  • 🌐 ZoneRules — rules defining how a time-zone offset changes over time, including daylight savings transitions
  • Robust error handling using check patterns to prevent runtime panics on invalid interop calls
  • Immutable API — every plus*, minus*, and with* method returns a new object
  • Familiar java.time semantics, ported to idiomatic Ballerina

Import

import kruutteri1/java_time_utils;Copy

Other versions

See more...

Metadata

Released date: 7 days ago

Version: 1.1.5

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.13.4

GraalVM compatible: Yes


Pull count

Total: 9

Current verison: 0


Weekly downloads


Source repository


Keywords

java-time

date

time

localdate

localdatetime

localtime

zone

time-zone

utility

java-interop

datetime

date-time


Contributors