or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-types.mddatetime-operations.mdduration-building.mdindex.mdlocal-datetime.mdordering.mdstring-parsing.md
tile.json

local-datetime.mddocs/

Local Date and Time Types

Enhanced functionality for local date and time types including arithmetic operations and property access. Local types represent dates and times without timezone information, making them ideal for calendar operations and user interface display.

Capabilities

Enhanced LocalDate Operations

Rich wrapper providing arithmetic operations and property access for LocalDate.

/**
 * Enhanced LocalDate with operator overloading and property access
 * @param ld The underlying Joda Time LocalDate
 */
implicit class RichLocalDate(ld: LocalDate) extends AnyVal {
  // Arithmetic operations
  def +(period: ReadablePeriod): LocalDate
  def -(period: ReadablePeriod): LocalDate
  
  // Property accessors
  def day: LocalDate.Property
  def week: LocalDate.Property
  def month: LocalDate.Property
  def year: LocalDate.Property
  
  // Fluent setters
  def withDay(day: Int): LocalDate
  def withMonth(month: Int): LocalDate
  def withYear(year: Int): LocalDate
}

Enhanced LocalDate Property Operations

Enhanced property operations for LocalDate components.

/**
 * Enhanced LocalDate property operations
 * @param pty The underlying LocalDate.Property
 */
implicit class RichLocalDateProperty(pty: LocalDate.Property) extends AnyVal {
  // Enhanced property operations for LocalDate fields
  // Provides fluent API for property manipulation
}

Enhanced LocalDateTime Operations

Rich wrapper providing arithmetic operations and property access for LocalDateTime.

/**
 * Enhanced LocalDateTime with operator overloading and property access
 * @param dt The underlying Joda Time LocalDateTime
 */
implicit class RichLocalDateTime(dt: LocalDateTime) extends AnyVal {
  // Arithmetic operations
  def +(period: ReadablePeriod): LocalDateTime
  def -(period: ReadablePeriod): LocalDateTime
  def +(duration: ReadableDuration): LocalDateTime
  def -(duration: ReadableDuration): LocalDateTime
  
  // Property accessors
  def millis: LocalDateTime.Property
  def second: LocalDateTime.Property
  def minute: LocalDateTime.Property
  def hour: LocalDateTime.Property
  def day: LocalDateTime.Property
  def month: LocalDateTime.Property
  def year: LocalDateTime.Property
  
  // Fluent setters
  def withSecond(second: Int): LocalDateTime
  def withMinute(minute: Int): LocalDateTime
  def withHour(hour: Int): LocalDateTime
  def withDay(day: Int): LocalDateTime
  def withMonth(month: Int): LocalDateTime
  def withYear(year: Int): LocalDateTime
}

Enhanced LocalDateTime Property Operations

Enhanced property operations for LocalDateTime components.

/**
 * Enhanced LocalDateTime property operations
 * @param pty The underlying LocalDateTime.Property
 */
implicit class RichLocalDateTimeProperty(pty: LocalDateTime.Property) extends AnyVal {
  // Enhanced property operations for LocalDateTime fields
  // Provides fluent API for property manipulation
}

Enhanced LocalTime Operations

Rich wrapper providing arithmetic operations and property access for LocalTime.

/**
 * Enhanced LocalTime with operator overloading and property access
 * @param lt The underlying Joda Time LocalTime
 */
implicit class RichLocalTime(lt: LocalTime) extends AnyVal {
  // Arithmetic operations
  def +(period: ReadablePeriod): LocalTime
  def -(period: ReadablePeriod): LocalTime
  def +(duration: ReadableDuration): LocalTime
  def -(duration: ReadableDuration): LocalTime
  
  // Property accessors
  def millis: LocalTime.Property
  def second: LocalTime.Property
  def minute: LocalTime.Property
  def hour: LocalTime.Property
  
  // Fluent setters
  def withSecond(second: Int): LocalTime
  def withMinute(minute: Int): LocalTime
  def withHour(hour: Int): LocalTime
  def withMillis(millis: Int): LocalTime
}

Enhanced LocalTime Property Operations

Enhanced property operations for LocalTime components.

/**
 * Enhanced LocalTime property operations
 * @param pty The underlying LocalTime.Property
 */
implicit class RichLocalTimeProperty(pty: LocalTime.Property) extends AnyVal {
  // Enhanced property operations for LocalTime fields
  // Provides fluent API for property manipulation
}

Usage Examples:

import com.github.nscala_time.time.Imports._

// LocalDate operations
val today = LocalDate.now()
val nextWeek = today + 1.week
val lastMonth = today - 1.month
val birthday = today.withMonth(12).withDay(25)

// LocalDate property access
val currentYear = today.year.get()
val endOfMonth = today.day.withMaximumValue()
val startOfYear = today.dayOfYear.withMinimumValue()

// LocalDateTime operations
val now = LocalDateTime.now()
val meetingTime = now
  .withHour(14)
  .withMinute(30)
  .withSecond(0)

val later = now + 2.hours + 30.minutes
val yesterday = now - 1.day

// LocalTime operations
val currentTime = LocalTime.now()
val lunchTime = currentTime.withHour(12).withMinute(0)
val afternoon = currentTime + 4.hours
val morning = currentTime - 6.hours

// Working with milliseconds
val preciseTime = currentTime.withMillis(500)
val currentMillis = currentTime.millis.get()

Static Factory Methods

Enhanced static factory methods for creating local date/time objects.

object StaticLocalDate {
  def now(): LocalDate
  def now(zone: DateTimeZone): LocalDate
  def now(chronology: Chronology): LocalDate
  def parse(str: String): LocalDate
}

object StaticLocalDateTime {
  def now(): LocalDateTime
  def now(zone: DateTimeZone): LocalDateTime
  def now(chronology: Chronology): LocalDateTime
  def parse(str: String): LocalDateTime
}

object StaticLocalTime {
  def now(): LocalTime
  def now(zone: DateTimeZone): LocalTime
  def now(chronology: Chronology): LocalTime
  def parse(str: String): LocalTime
}

Static Factory Usage Examples:

import com.github.nscala_time.time.Imports._

// Current local date/time
val today = LocalDate.now()
val now = LocalDateTime.now()
val currentTime = LocalTime.now()

// Parsing from strings
val specificDate = LocalDate.parse("2023-12-25")
val specificDateTime = LocalDateTime.parse("2023-12-25T14:30:00")
val specificTime = LocalTime.parse("14:30:00")

// With specific time zones (gets local component)
val localInUTC = LocalDate.now(DateTimeZone.UTC)
val localInTokyo = LocalDateTime.now(DateTimeZone.forID("Asia/Tokyo"))

Conversion Between Local Types

Converting between different local date/time representations.

import com.github.nscala_time.time.Imports._

val date = LocalDate.now()
val time = LocalTime.now()
val dateTime = LocalDateTime.now()

// Combining LocalDate and LocalTime to LocalDateTime
val combined = date.toLocalDateTime(time)

// Extracting components
val dateFromDateTime = dateTime.toLocalDate
val timeFromDateTime = dateTime.toLocalTime

// Converting to DateTime (requires timezone)
val withTimezone = dateTime.toDateTime(DateTimeZone.getDefault)
val atUTC = dateTime.toDateTime(DateTimeZone.UTC)

Calendar Operations

Common calendar operations using local date/time types.

import com.github.nscala_time.time.Imports._

val today = LocalDate.now()

// Month boundaries
val startOfMonth = today.day.withMinimumValue()
val endOfMonth = today.day.withMaximumValue()

// Year boundaries
val startOfYear = today.dayOfYear.withMinimumValue()
val endOfYear = today.dayOfYear.withMaximumValue()

// Week operations
val startOfWeek = today.dayOfWeek.withMinimumValue()  // Monday
val endOfWeek = today.dayOfWeek.withMaximumValue()    // Sunday

// Business day calculations
val nextMonday = today.dayOfWeek.setCopy(DateTimeConstants.MONDAY)
val nextFriday = today.dayOfWeek.setCopy(DateTimeConstants.FRIDAY)

// Time operations
val timeNow = LocalTime.now()
val startOfDay = timeNow.withMillisOfDay(0)  // 00:00:00.000
val noon = timeNow.withHour(12).withMinute(0).withSecond(0)
val endOfDay = timeNow.withTime(23, 59, 59, 999)  // 23:59:59.999

Comparison and Ordering

Local date/time types support natural ordering and comparison operations.

import com.github.nscala_time.time.Imports._

val date1 = LocalDate.now()
val date2 = date1 + 1.day

// Comparisons
val isBefore = date1 < date2  // true
val isAfter = date1 > date2   // false
val isEqual = date1 == date1  // true

// Sorting collections
val dates = List(
  LocalDate.parse("2023-12-25"),
  LocalDate.parse("2023-01-01"),
  LocalDate.parse("2023-06-15")
)

val sortedDates = dates.sorted  // Chronological order
val reverseSorted = dates.sorted(Ordering[LocalDate].reverse)

// Working with ranges (if available through additional operations)
val startDate = LocalDate.parse("2023-01-01")
val endDate = LocalDate.parse("2023-01-31")

// Generate sequence of dates (custom implementation)
def dateRange(start: LocalDate, end: LocalDate): List[LocalDate] = {
  def loop(current: LocalDate, acc: List[LocalDate]): List[LocalDate] = {
    if (current > end) acc.reverse
    else loop(current + 1.day, current :: acc)
  }
  loop(start, Nil)
}

val januaryDates = dateRange(startDate, endDate)