Skip to content

Commit

Permalink
ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Dec 20, 2024
1 parent 5cdf2dd commit 43a9dfb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class InstantTest {
FromTest("Thu, 05 Nov 2020 19:22:37 +1245", 1604558257, 0),
FromTest("Thu, 05 Nov 2020 19:22:37 -1245", 1604650057, 0),
)

@Test
fun testFromRfc5322() {
for ((idx, test) in rfc5322Tests.withIndex()) {
Expand Down Expand Up @@ -299,4 +300,3 @@ class V2JavaSdkTests {
// (2) - The input year in those tests is NOT valid and should never have
// been accepted by the parser.
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,39 @@ internal object DateTimeFormats {
// e.g. "2020-11-05T19:22:37+00:00"
val ISO_8601 = DateTimeComponents.Format {
// Two possible date formats: YYYY-MM-DD or YYYYMMDD
alternativeParsing ({
date(LocalDate.Format { year(); monthNumber(); dayOfMonth() })
alternativeParsing({
date(
LocalDate.Format {
year()
monthNumber()
dayOfMonth()
},
)
}) {
date(LocalDate.Format {
year(); char('-'); monthNumber(); char('-'); dayOfMonth()
})
date(
LocalDate.Format {
year()
char('-')
monthNumber()
char('-')
dayOfMonth()
},
)
}

char('T')

// Two possible time formats: HH:MM:SS or HHMMSS
alternativeParsing({
hour(); minute(); second()
hour()
minute()
second()
}) {
hour(); char(':'); minute(); char(':'); second()
hour()
char(':')
minute()
char(':')
second()
}

// Fractional seconds (up to 6 digits)
Expand Down Expand Up @@ -90,4 +108,4 @@ internal object DateTimeFormats {
offset(UtcOffset.Formats.FOUR_DIGITS)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public actual class Instant(internal val delegate: ktInstant) : Comparable<Insta
/**
* Encode the [Instant] as a string into the format specified by [TimestampFormat]
*/
public actual fun format(fmt: TimestampFormat): String {
return when (fmt) {
TimestampFormat.EPOCH_SECONDS -> {
val s = delegate.epochSeconds.toString()
val ns = if (delegate.nanosecondsOfSecond != 0) {
".${delegate.nanosecondsOfSecond.toString().padStart(9, '0').trimEnd('0')}"
} else ""
s + ns
public actual fun format(fmt: TimestampFormat): String = when (fmt) {
TimestampFormat.EPOCH_SECONDS -> {
val s = delegate.epochSeconds.toString()
val ns = if (delegate.nanosecondsOfSecond != 0) {
".${delegate.nanosecondsOfSecond.toString().padStart(9, '0').trimEnd('0')}"
} else {
""
}
else -> delegate.format(fmt.asDateTimeFormat())
s + ns
}
else -> delegate.format(fmt.asDateTimeFormat())
}

/**
Expand Down

0 comments on commit 43a9dfb

Please sign in to comment.