Module java_time_utils

kruutteri1/java_time_utils

1.0.7

Overview

A Ballerina wrapper around java.timeLocalDate, LocalDateTime, and LocalTime, and other core helper and enum classes like Month and DayOfWeek for working with dates, times, and temporal components without time zones.

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, immutable values, and predictable behavior, without reaching for a full-blown time-zone library when you don't need one.

Installation

Copy
# Ballerina.toml
[[dependency]]
org = "kruutteri1"
name = "java_time_utils"
version = "1.0.7"  # 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
  • 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: 3 days ago

Version: 1.0.7

License: Apache-2.0


Compatibility

Platform: java21

Ballerina version: 2201.13.4

GraalVM compatible: Yes


Pull count

Total: 5

Current verison: 0


Weekly downloads


Source repository


Keywords

java-time

date

time

localdate

localdatetime

localtime


Contributors