mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
feat: finalized docs, lmk if i missed something
This commit is contained in:
parent
37c8a6f9ce
commit
829494e304
2 changed files with 63 additions and 15 deletions
|
@ -243,7 +243,7 @@ impl DateTime {
|
||||||
|
|
||||||
// TODO: Implement more locales for chrono-locale.
|
// TODO: Implement more locales for chrono-locale.
|
||||||
|
|
||||||
/// Generates a string from the `DateTime` value interpreted as **local time**
|
/// Generates a string from the `DateTime` value interpreted as the specified timezone
|
||||||
/// and a format string. The format string should contain tokens, which will
|
/// and a format string. The format string should contain tokens, which will
|
||||||
/// replace to certain date/time values described by the `DateTime` object.
|
/// replace to certain date/time values described by the `DateTime` object.
|
||||||
/// For more details, see the [accepted formatter tokens](https://docs.rs/chrono/latest/chrono/format/strftime/index.html).
|
/// For more details, see the [accepted formatter tokens](https://docs.rs/chrono/latest/chrono/format/strftime/index.html).
|
||||||
|
|
|
@ -45,17 +45,6 @@ export type DateTimeValues = {
|
||||||
export type DateTime = {
|
export type DateTime = {
|
||||||
unixTimestamp: number,
|
unixTimestamp: number,
|
||||||
unixTimestampMillis: number,
|
unixTimestampMillis: number,
|
||||||
|
|
||||||
toIsoDate: (self: DateTime) -> string,
|
|
||||||
toLocalTime: (self: DateTime) -> DateTimeValues & { month: number },
|
|
||||||
toUniversalTime: (self: DateTime) -> DateTimeValues & { month: number },
|
|
||||||
|
|
||||||
formatTime: (
|
|
||||||
self: DateTime,
|
|
||||||
timezone: Timezone,
|
|
||||||
formatString: string,
|
|
||||||
locale: Locale
|
|
||||||
) -> string,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
--[=[
|
--[=[
|
||||||
|
@ -127,7 +116,7 @@ end
|
||||||
|
|
||||||
Returns a new `DateTime` using the given units from a UTC time. The
|
Returns a new `DateTime` using the given units from a UTC time. The
|
||||||
values accepted are similar to those found in the time value table
|
values accepted are similar to those found in the time value table
|
||||||
returned by `to_universal_time`.
|
returned by `toUniversalTime`.
|
||||||
|
|
||||||
- Date units (year, month, day) that produce an invalid date will raise an error. For example, January 32nd or February 29th on a non-leap year.
|
- Date units (year, month, day) that produce an invalid date will raise an error. For example, January 32nd or February 29th on a non-leap year.
|
||||||
- Time units (hour, minute, second, millisecond) that are outside their normal range are valid. For example, 90 minutes will cause the hour to roll over by 1; -10 seconds will cause the minute value to roll back by 1.
|
- Time units (hour, minute, second, millisecond) that are outside their normal range are valid. For example, 90 minutes will cause the hour to roll over by 1; -10 seconds will cause the minute value to roll back by 1.
|
||||||
|
@ -146,7 +135,7 @@ end
|
||||||
|
|
||||||
Returns a new `DateTime` using the given units from a local time. The
|
Returns a new `DateTime` using the given units from a local time. The
|
||||||
values accepted are similar to those found in the time value table
|
values accepted are similar to those found in the time value table
|
||||||
returned by `to_local_time`.
|
returned by `toLocalTime`.
|
||||||
|
|
||||||
- Date units (year, month, day) that produce an invalid date will raise an error. For example, January 32nd or February 29th on a non-leap year.
|
- Date units (year, month, day) that produce an invalid date will raise an error. For example, January 32nd or February 29th on a non-leap year.
|
||||||
- Time units (hour, minute, second, millisecond) that are outside their normal range are valid. For example, 90 minutes will cause the hour to roll over by 1; -10 seconds will cause the minute value to roll back by 1.
|
- Time units (hour, minute, second, millisecond) that are outside their normal range are valid. For example, 90 minutes will cause the hour to roll over by 1; -10 seconds will cause the minute value to roll back by 1.
|
||||||
|
@ -164,7 +153,7 @@ end
|
||||||
@within DateTime
|
@within DateTime
|
||||||
|
|
||||||
Returns a `DateTime` from an ISO 8601 date-time string in UTC
|
Returns a `DateTime` from an ISO 8601 date-time string in UTC
|
||||||
time, such as those returned by `to_iso_date`. If the
|
time, such as those returned by `toIsoDate`. If the
|
||||||
string parsing fails, the function returns `nil`.
|
string parsing fails, the function returns `nil`.
|
||||||
|
|
||||||
An example ISO 8601 date-time string would be `2020-01-02T10:30:45Z`,
|
An example ISO 8601 date-time string would be `2020-01-02T10:30:45Z`,
|
||||||
|
@ -177,4 +166,63 @@ function dateTime.fromIsoDate(iso_date: string): DateTime?
|
||||||
return nil :: any
|
return nil :: any
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[=[
|
||||||
|
@within DateTime
|
||||||
|
|
||||||
|
Formats a date as a ISO 8601 date-time string, returns None if the DateTime
|
||||||
|
object is invalid. The value returned by this function could be passed to
|
||||||
|
`fromLocalTime` to produce the original `DateTime` object.
|
||||||
|
|
||||||
|
@return ISO 8601 formatted string
|
||||||
|
]=]
|
||||||
|
function dateTime:toIsoDate(): string
|
||||||
|
return nil :: any
|
||||||
|
end
|
||||||
|
|
||||||
|
--[=[
|
||||||
|
@within DateTime
|
||||||
|
|
||||||
|
Converts the value of this `DateTime` object to local time. The returned table
|
||||||
|
contains the following keys: `Year`, `Month`, `Day`, `Hour`, `Minute`, `Second`,
|
||||||
|
`Millisecond`. For more details, see the time value table in this data type's
|
||||||
|
description. The values within this table could be passed to `fromLocalTime`
|
||||||
|
to produce the original `DateTime` object.
|
||||||
|
|
||||||
|
@return A table of DateTime values
|
||||||
|
]=]
|
||||||
|
function dateTime:toLocalTime(): DateTimeValues & { month: number }
|
||||||
|
return nil :: any
|
||||||
|
end
|
||||||
|
|
||||||
|
--[=[
|
||||||
|
@within DateTime
|
||||||
|
|
||||||
|
Converts the value of this `DateTime` object to universal time. The returned table
|
||||||
|
contains the following keys: `Year`, `Month`, `Day`, `Hour`, `Minute`, `Second`,
|
||||||
|
`Millisecond`. For more details, see the time value table in this data type's
|
||||||
|
description. The values within this table could be passed to `fromUniversalTime`
|
||||||
|
to produce the original `DateTime` object.
|
||||||
|
|
||||||
|
@return A table of DateTime values
|
||||||
|
]=]
|
||||||
|
function dateTime:toUniversalTime(): DateTimeValues & { month: number }
|
||||||
|
return nil :: any
|
||||||
|
end
|
||||||
|
|
||||||
|
--[=[
|
||||||
|
@within DateTime
|
||||||
|
|
||||||
|
Generates a string from the `DateTime` value interpreted as the specified timezone
|
||||||
|
and a format string. The format string should contain tokens, which will
|
||||||
|
replace to certain date/time values described by the `DateTime` object.
|
||||||
|
|
||||||
|
@param timezone The timezone the formatted time string should follow
|
||||||
|
@param formatString A format string of strfttime items. See [chrono docs](https://docs.rs/chrono/latest/chrono/format/strftime/index.html).
|
||||||
|
@param locale The locale the time should be formatted in
|
||||||
|
@return A table of DateTime values
|
||||||
|
]=]
|
||||||
|
function dateTime:formatTime(timezone: Timezone, formatString: string, locale: Locale): string
|
||||||
|
return nil :: any
|
||||||
|
end
|
||||||
|
|
||||||
return dateTime
|
return dateTime
|
||||||
|
|
Loading…
Add table
Reference in a new issue