Lampese/mathplotlib/ticker/date does not have a README file
pub(all) suberror DateError {
InvalidDate(message~ : String)
InvalidFormat(message~ : String)
}pub struct AutoDateFormatter {
// private fields
}fn AutoDateFormatter::format_array(self : AutoDateFormatter, values : Array[Double], pos? : Int) -> Array[String] raise DateErrorfn AutoDateFormatter::format_dates(self : AutoDateFormatter, values : Array[DateTime], pos? : Int) -> Array[String] raise DateErrorfn AutoDateFormatter::format_ticks(self : AutoDateFormatter, values : Array[Double]) -> Array[String] raise DateErrorfn AutoDateFormatter::format_value(self : AutoDateFormatter, value : Double, pos? : Int) -> String raise DateErrorfn AutoDateFormatter::new(locator? : DateLocator, tz? : String, timezone? : DateTimeZone, default_format? : String, usetex? : Bool) -> AutoDateFormatter raise DateErrortest {
let formatter = @date.AutoDateFormatter::new(
locator=@date.minute_locator(interval=30),
)
assert_eq(formatter.unit_scale(), 1.0 / 1440.0)
assert_eq(formatter.format_value(0.0), "01 00:00")
}fn AutoDateFormatter::with_default_format(self : AutoDateFormatter, format : String) -> AutoDateFormatterfn AutoDateFormatter::with_locator(self : AutoDateFormatter, locator : DateLocator) -> AutoDateFormatterfn AutoDateFormatter::with_locator_unit(self : AutoDateFormatter, unit : Double) -> AutoDateFormatterfn AutoDateFormatter::with_offset(self : AutoDateFormatter, offset_minutes : Int) -> AutoDateFormatter raise DateErrorfn AutoDateFormatter::with_scale(self : AutoDateFormatter, scale : Double, format : DateScaleFormat) -> AutoDateFormatter raise DateErrorfn AutoDateFormatter::with_scaled(self : AutoDateFormatter, entries : Array[(Double, DateScaleFormat)]) -> AutoDateFormatter raise DateErrorfn AutoDateFormatter::with_timezone(self : AutoDateFormatter, timezone : DateTimeZone) -> AutoDateFormatterpub struct AutoDateLocator {
// private fields
}fn AutoDateLocator::get_locator(self : AutoDateLocator, first : DateTime, last : DateTime) -> DateLocator raise DateErrorfn AutoDateLocator::get_locator_for_range(self : AutoDateLocator, lower : Double, upper : Double) -> DateLocator raise DateErrorfn AutoDateLocator::new(context? : DateParserContext, tz? : String, timezone? : DateTimeZone, minticks? : Int, maxticks? : DateMaxTicks, interval_multiples? : Bool) -> AutoDateLocator raise DateErrortest {
let locator = @date.AutoDateLocator::new(maxticks=@date.All(5))
let first = @date.datetime(2024, 1, 1).to_ordinal()
let last = @date.datetime(2024, 6, 1).to_ordinal()
assert_true(!locator.tick_values(first, last).is_empty())
assert_eq(locator.frequency(), @date.Month)
}fn AutoDateLocator::nonsingular(_self : AutoDateLocator, lower : Double, upper : Double) -> (Double, Double)fn AutoDateLocator::tick_values(self : AutoDateLocator, lower : Double, upper : Double) -> Array[Double] raise DateErrorfn AutoDateLocator::with_interval_multiples(self : AutoDateLocator, enabled : Bool) -> AutoDateLocatorfn AutoDateLocator::with_intervals(self : AutoDateLocator, frequency : DateFrequency, values : Array[Int]) -> AutoDateLocator raise DateErrorfn AutoDateLocator::with_maxticks(self : AutoDateLocator, value : DateMaxTicks) -> AutoDateLocator raise DateErrorfn AutoDateLocator::with_minticks(self : AutoDateLocator, count : Int) -> AutoDateLocator raise DateErrorfn AutoDateLocator::with_offset(self : AutoDateLocator, offset_minutes : Int) -> AutoDateLocator raise DateErrorfn AutoDateLocator::with_timezone(self : AutoDateLocator, timezone : DateTimeZone) -> AutoDateLocatorpub(all) enum AutoDateWarning {
IntervalFallback(DateFrequency, Int)
DistantMicroseconds
} derive(Eq, Debug)pub struct ConciseDateConverter {
// private fields
}fn ConciseDateConverter::axisinfo(self : ConciseDateConverter, unit? : DateTimeZone) -> DateAxisInfo raise DateErrorfn ConciseDateConverter::convert(self : ConciseDateConverter, values : Array[DateTime]) -> Array[Double]fn ConciseDateConverter::default_unit(self : ConciseDateConverter, value : DateTime) -> DateTimeZonefn ConciseDateConverter::default_units(self : ConciseDateConverter, values : Array[DateTime]) -> DateTimeZone?fn ConciseDateConverter::new(formats? : Array[String], zero_formats? : Array[String], offset_formats? : Array[String], show_offset? : Bool, interval_multiples? : Bool) -> ConciseDateConverterpub struct ConciseDateFormatter {
// private fields
}fn ConciseDateFormatter::format_data_short(self : ConciseDateFormatter, value : Double) -> String raise DateErrorfn ConciseDateFormatter::format_ticks(self : ConciseDateFormatter, values : Array[Double], inverted? : Bool) -> Array[String] raise DateErrorfn ConciseDateFormatter::with_default_format(self : ConciseDateFormatter, format : String) -> ConciseDateFormatterfn ConciseDateFormatter::with_offset(self : ConciseDateFormatter, offset_minutes : Int) -> ConciseDateFormatter raise DateErrorfn ConciseDateFormatter::with_show_offset(self : ConciseDateFormatter, show_offset : Bool) -> ConciseDateFormatterfn ConciseDateFormatter::with_timezone(self : ConciseDateFormatter, timezone : DateTimeZone) -> ConciseDateFormatterfn ConciseDateFormatter::with_usetex(self : ConciseDateFormatter, usetex : Bool) -> ConciseDateFormatterpub struct DateAxisInfo {
// private fields
}pub struct DateConverter {
// private fields
}fn DateConverter::axisinfo(self : DateConverter, unit? : DateTimeZone) -> DateAxisInfo raise DateErrortest {
let converter = @date.DateConverter::new()
let info = converter.axisinfo()
let values = converter.convert([
@date.datetime(2024, 1, 1),
@date.datetime(2024, 1, 2, hour=16),
])
let ticks = info.major_locator().tick_values(values[0], values[1])
assert_true(!info.major_formatter().format_values(ticks).is_empty())
}pub struct DateFormatter {
format : String
offset_minutes : Int
timezone : DateTimeZone?
// private fields
}fn DateFormatter::format_values(self : DateFormatter, values : Array[Double], inverted? : Bool) -> Array[String]fn DateFormatter::offset_label(self : DateFormatter, values : Array[Double], inverted? : Bool) -> Stringfn DateFormatter::with_offset(self : DateFormatter, offset_minutes : Int) -> DateFormatter raise DateErrortest {
let formatter = @date.date_formatter("%H:%M %z %Z").with_offset(345)
assert_eq(formatter.offset_minutes(), 345)
assert_eq(formatter.format_value(0.0), "05:45 +0545 UTC+05:45")
}pub struct DateLocator {
kind : LocatorKind
interval : Int
selector : Int
secondary : Int
selector_enabled : Bool
offset_minutes : Int
// private fields
}fn DateLocator::tick_values_checked(self : DateLocator, lower : Double, upper : Double) -> Array[Double] raise DateErrorfn DateLocator::with_offset(self : DateLocator, offset_minutes : Int) -> DateLocator raise DateErrortest {
let locator = try! @date.hour_locator().with_offset(90)
assert_eq(locator.offset_minutes(), 90)
}pub struct DateParserContext {
// private fields
}fn DateParserContext::from_posix(spec : String, clock? : () -> Int64) -> DateParserContext raise DateErrorfn DateParserContext::from_tzif(data : Bytes, clock? : () -> Int64) -> DateParserContext raise DateErrorfn DateParserContext::with_local_info(self : DateParserContext, standard_seconds : Int, daylight_seconds : Int, names : Array[String]) -> DateParserContext raise DateErrorpub struct DateStringParser {
// private fields
}fn DateStringParser::new(context? : DateParserContext, reference_year? : Int) -> DateStringParser raise DateErrortest {
let context = @date.DateParserContext::from_posix(
"EST5EDT,M3.2.0/2,M11.1.0/2",
clock=fn() { 1781524800000L },
)
let parser = @date.DateStringParser::new(context~)
let value = @date.datestr2num("Nov 3, 2024 01:30 EST", parser~)
assert_eq(@date.num2date(value).hour(), 6)
}fn DateStringParser::parse(self : DateStringParser, text : String, default_date? : DateTime) -> DateTime raise DateErrorfn DateStringParser::parse_many(self : DateStringParser, texts : Array[String], default_date? : DateTime) -> Array[DateTime] raise DateErrorfn DateStringParser::to_number(self : DateStringParser, text : String, default_date? : DateTime) -> Double raise DateErrorfn DateStringParser::to_numbers(self : DateStringParser, texts : Array[String], default_date? : DateTime) -> Array[Double] raise DateErrorpub struct DateTime {
year : Int
month : Int
day : Int
hour : Int
minute : Int
second : Int
microsecond : Int
offset_minutes : Int
// private fields
}test {
let value = @date.datetime(1900, 1, 1, offset_seconds=561)
assert_eq(value.offset_seconds(), 561)
assert_eq(@date.format_date(value.with_offset(0), "%H:%M:%S"), "23:50:39")
}test {
let value = @date.datetime(2243, 10, 17, microsecond=123456)
let shifted = value.with_offset(-480)
assert_eq(shifted.day(), 16)
assert_eq(shifted.hour(), 16)
assert_eq(shifted.microsecond(), 123456)
}pub struct DateTimeZone {
// private fields
}pub struct DayLocator {
// private fields
}fn DayLocator::new(bymonthday? : Array[Int], bymonthday_value? : Int, interval? : Int, tz? : String, timezone? : DateTimeZone, context? : DateParserContext, null? : Array[String]) -> DayLocator raise DateErrortest {
let context = @date.DateParserContext::utc(clock=fn() { 1781524800123L })
let locator = @date.DayLocator::new(bymonthday_value=-1, tz="UTC", context~)
let values = locator.tick_values(
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1)),
@date.RRuleDateTime::naive(@date.datetime(2024, 3, 1)),
)
assert_eq(values.length(), 2)
}fn DayLocator::tick_values(self : DayLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorpub struct HourLocator {
// private fields
}fn HourLocator::new(byhour? : Array[Int], byhour_value? : Int, interval? : Int, tz? : String, timezone? : DateTimeZone, context? : DateParserContext, null? : Array[String]) -> HourLocator raise DateErrortest {
let context = @date.DateParserContext::utc(clock=fn() { 1781524800123L })
let locator = @date.HourLocator::new(byhour=[0, 12], tz="UTC", context~)
let values = locator.tick_values(
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1)),
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 2)),
)
assert_eq(values.length(), 3)
}fn HourLocator::tick_values(self : HourLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorfn HourLocator::with_offset(self : HourLocator, offset_minutes : Int) -> HourLocator raise DateErrorpub(all) enum LocatorKind {
Automatic
Days
BusinessDays
Years
Months
Weekdays
NthWeekdays
Recurrence
Hours
Minutes
Seconds
Microseconds
}pub struct MicrosecondLocator {
// private fields
}fn MicrosecondLocator::new(interval? : Double, tz? : String, timezone? : DateTimeZone, context? : DateParserContext) -> MicrosecondLocator raise DateErrortest {
let locator = @date.MicrosecondLocator::new(interval=0.5, tz="UTC")
let first = @date.RRuleDateTime::naive(@date.datetime(1970, 1, 1))
let last = @date.RRuleDateTime::naive(
@date.datetime(1970, 1, 1, microsecond=3),
)
assert_eq(locator.tick_values(first, last).length(), 9)
assert_eq(locator.as_locator().interval_value(), 0.5)
}fn MicrosecondLocator::nonsingular(self : MicrosecondLocator, lower : Double, upper : Double) -> (Double, Double)fn MicrosecondLocator::tick_values(self : MicrosecondLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorfn MicrosecondLocator::with_offset(self : MicrosecondLocator, offset_minutes : Int) -> MicrosecondLocator raise DateErrorfn MicrosecondLocator::with_timezone(self : MicrosecondLocator, timezone : DateTimeZone) -> MicrosecondLocatorpub struct MinuteLocator {
// private fields
}fn MinuteLocator::new(byminute? : Array[Int], byminute_value? : Int, interval? : Int, tz? : String, timezone? : DateTimeZone, context? : DateParserContext, null? : Array[String]) -> MinuteLocator raise DateErrortest {
let context = @date.DateParserContext::utc(clock=fn() { 1781524800123L })
let locator = @date.MinuteLocator::new(byminute=[0, 30], tz="UTC", context~)
let values = locator.tick_values(
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1)),
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1, hour=1)),
)
assert_eq(values.length(), 3)
}fn MinuteLocator::tick_values(self : MinuteLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorfn MinuteLocator::with_offset(self : MinuteLocator, offset_minutes : Int) -> MinuteLocator raise DateErrorpub struct MonthLocator {
// private fields
}fn MonthLocator::new(bymonth? : Array[Int], bymonth_value? : Int, bymonthday? : Array[Int], bymonthday_value? : Int, interval? : Int, tz? : String, timezone? : DateTimeZone, context? : DateParserContext, null? : Array[String]) -> MonthLocator raise DateErrortest {
let context = @date.DateParserContext::utc(clock=fn() { 1781524800123L })
let locator = @date.MonthLocator::new(tz="UTC", context~)
let values = locator.tick_values(
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1)),
@date.RRuleDateTime::naive(@date.datetime(2024, 3, 1)),
)
assert_eq(values.length(), 3)
}fn MonthLocator::tick_values(self : MonthLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorfn MonthLocator::with_offset(self : MonthLocator, offset_minutes : Int) -> MonthLocator raise DateErrorpub struct RRule {
// private fields
}test {
let rule = @date.rrule(@date.Daily, @date.datetime(2024, 1, 1), cache=true)
assert_eq(rule.iter().take(3).to_array().map(value => value.day()), [1, 2, 3])
assert_eq(rule.iter().next().unwrap().day(), 1)
}fn RRule::replace(self : RRule, frequency? : RRuleFrequency, dtstart? : DateTime, interval? : Int, wkst? : Int, bymonth? : Array[Int], bymonthday? : Array[Int], byyearday? : Array[Int], byweekno? : Array[Int], byeaster? : Array[Int], byweekday? : Array[Int], byhour? : Array[Int], byminute? : Array[Int], bysecond? : Array[Int], bysetpos? : Array[Int], count? : Int, until? : DateTime, clear? : Array[String], cache? : Bool) -> RRule raise DateErrortest {
let zone = try! @date.timezone(-300, transitions=[
try! @date.timezone_transition(@date.datetime(2024, 3, 10, hour=7), -240),
])
let rule = try! @date.rrule(
@date.RRuleFrequency::Daily,
@date.datetime(2024, 3, 9, hour=2, offset_minutes=-300),
byhour=[2],
).with_timezone(zone)
assert_eq(rule.locator().offset_minutes(), -300)
}pub struct RRuleDateIterator {
// private fields
}pub struct RRuleDateTime {
// private fields
}fn RRuleDateTime::from_local(value : DateTime, timezone : DateTimeZone, fold? : Bool) -> RRuleDateTime raise DateErrorpub(all) enum RRuleFrequency {
Yearly
Monthly
Weekly
Daily
Hourly
Minutely
Secondly
}pub struct RRuleLocator {
// private fields
}fn RRuleLocator::new(rule : RRuleWrapper, tz? : String, timezone? : DateTimeZone) -> RRuleLocator raise DateErrorfn RRuleLocator::tick_values(self : RRuleLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrortest {
let first = @date.RRuleDateTime::naive(@date.datetime(2024, 1, 1))
let last = @date.RRuleDateTime::naive(@date.datetime(2024, 1, 3))
let rule = @date.RRuleWrapper::new(@date.Daily, dtstart=first)
let locator = @date.RRuleLocator::new(rule, tz="UTC")
assert_eq(locator.tick_values(first, last).length(), 3)
rule.set(frequency=@date.Hourly, interval=12)
assert_eq(locator.as_locator().interval(), 12)
}fn RRuleLocator::with_offset(self : RRuleLocator, offset_minutes : Int) -> RRuleLocator raise DateErrorpub struct RRuleSet {
// private fields
}test {
let set = @date.rruleset(cache=true)
set.rrule(@date.rrule(@date.Daily, @date.datetime(2024, 1, 1), count=3))
set.exdate(@date.datetime(2024, 1, 2))
assert_eq(set.iter().to_array().map(value => value.day()), [1, 3])
}pub struct RRuleWrapper {
// private fields
}fn RRuleWrapper::after(self : RRuleWrapper, value : RRuleDateTime, inc? : Bool) -> RRuleDateTime? raise DateErrorfn RRuleWrapper::before(self : RRuleWrapper, value : RRuleDateTime, inc? : Bool) -> RRuleDateTime? raise DateErrorfn RRuleWrapper::between(self : RRuleWrapper, after : RRuleDateTime, before : RRuleDateTime, inc? : Bool) -> Array[RRuleDateTime] raise DateErrortest {
let rule = @date.RRuleWrapper::new(
@date.Minutely,
dtstart=@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1, hour=12)),
interval=1440,
byhour=[12],
byminute=[0],
count=2,
cache=true,
)
let reader = rule.checked_raw_iter()
assert_eq(reader.next().unwrap().date().day(), 1)
rule.set(byhour=[13])
assert_eq(reader.next().unwrap().date().day(), 2)
assert_true(
try {
ignore(rule.occurrence_count())
false
} catch {
_ => true
},
)
}fn RRuleWrapper::new(frequency : RRuleFrequency, timezone? : DateTimeZone, context? : DateParserContext, dtstart? : RRuleDateTime, until? : RRuleDateTime, interval? : Int, wkst? : Int, count? : Int, bymonth? : Array[Int], bymonthday? : Array[Int], bymonth_value? : Int, bymonthday_value? : Int, byyearday? : Array[Int], byweekno? : Array[Int], byeaster? : Array[Int], byweekday? : Array[Int], byhour? : Array[Int], byminute? : Array[Int], bysecond? : Array[Int], bysetpos? : Array[Int], byweekdays? : Array[RelativeWeekday], cache? : Bool, null? : Array[String]) -> RRuleWrapper raise DateErrortest {
let start = @date.RRuleDateTime::naive(@date.datetime(2024, 1, 1))
let rule = @date.RRuleWrapper::new(@date.Daily, dtstart=start, count=3)
assert_eq(
rule.xafter(start, count=2, inc=true).map(value => value.date().day()),
[1, 2],
)
rule.set(interval=2)
assert_eq(rule.raw_iter().to_array().map(value => value.date().day()), [
1, 3, 5,
])
}fn RRuleWrapper::set(self : RRuleWrapper, frequency? : RRuleFrequency, dtstart? : RRuleDateTime, until? : RRuleDateTime, interval? : Int, wkst? : Int, count? : Int, bymonth? : Array[Int], bymonthday? : Array[Int], bymonth_value? : Int, bymonthday_value? : Int, byyearday? : Array[Int], byweekno? : Array[Int], byeaster? : Array[Int], byweekday? : Array[Int], byhour? : Array[Int], byminute? : Array[Int], bysecond? : Array[Int], bysetpos? : Array[Int], byweekdays? : Array[RelativeWeekday], cache? : Bool, null? : Array[String]) -> Unit raise DateErrorfn RRuleWrapper::xafter(self : RRuleWrapper, value : RRuleDateTime, count? : Int, inc? : Bool) -> Array[RRuleDateTime] raise DateErrorimpl Eq for RelativeDeltafn RelativeDelta::add_timedelta(self : RelativeDelta, delta : TimeDelta) -> RelativeDelta raise DateErrorfn RelativeDelta::new(years? : Int64, months? : Int64, days? : Double, weeks? : Double, leapdays? : Double, hours? : Double, minutes? : Double, seconds? : Double, microseconds? : Double, year? : Int, month? : Int, day? : Int, hour? : Int, minute? : Int, second? : Int, microsecond? : Int, weekday? : Int, on_weekday? : RelativeWeekday, yearday? : Int, nlyearday? : Int) -> RelativeDelta raise DateErrortest {
let delta = @date.RelativeDelta::new(days=1.5, hours=2.0).normalized()
assert_eq((delta.days(), delta.hours()), (1.0, 14.0))
let next = @date.datetime(2024, 1, 31).add_relative_delta(
@date.RelativeDelta::new(months=1L),
)
assert_eq((next.month(), next.day()), (2, 29))
}fn RelativeDelta::subtract(self : RelativeDelta, other : RelativeDelta) -> RelativeDelta raise DateErrorpub struct SecondLocator {
// private fields
}fn SecondLocator::new(bysecond? : Array[Int], bysecond_value? : Int, interval? : Int, tz? : String, timezone? : DateTimeZone, context? : DateParserContext, null? : Array[String]) -> SecondLocator raise DateErrortest {
let context = @date.DateParserContext::utc(clock=fn() { 1781524800123L })
let locator = @date.SecondLocator::new(bysecond=[0, 30], tz="UTC", context~)
let values = locator.tick_values(
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1)),
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1, minute=1)),
)
assert_eq(values.length(), 3)
}fn SecondLocator::tick_values(self : SecondLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorfn SecondLocator::with_offset(self : SecondLocator, offset_minutes : Int) -> SecondLocator raise DateErrorpub struct TimeZoneTransition {
// private fields
}pub struct WeekdayLocator {
// private fields
}fn WeekdayLocator::new(byweekday? : Array[Int], byweekday_value? : Int, byweekdays? : Array[RelativeWeekday], on_weekday? : RelativeWeekday, interval? : Int, tz? : String, timezone? : DateTimeZone, context? : DateParserContext, null? : Array[String]) -> WeekdayLocator raise DateErrortest {
let context = @date.DateParserContext::utc(clock=fn() { 1781524800123L })
let locator = @date.WeekdayLocator::new(tz="UTC", context~)
let values = locator.tick_values(
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 1)),
@date.RRuleDateTime::naive(@date.datetime(2024, 1, 8)),
)
assert_eq(values.length(), 1)
}fn WeekdayLocator::tick_values(self : WeekdayLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorfn WeekdayLocator::with_offset(self : WeekdayLocator, offset_minutes : Int) -> WeekdayLocator raise DateErrorpub struct YearLocator {
// private fields
}fn YearLocator::new(base? : Int, month? : Int, day? : Int, tz? : String, timezone? : DateTimeZone, context? : DateParserContext) -> YearLocator raise DateErrortest {
let context = @date.DateParserContext::utc(clock=fn() { 1781524800123L })
let locator = @date.YearLocator::new(
base=5,
month=7,
day=4,
tz="UTC",
context~,
)
let values = locator.tick_values(
@date.RRuleDateTime::naive(@date.datetime(2021, 5, 1)),
@date.RRuleDateTime::naive(@date.datetime(2028, 1, 1)),
)
assert_eq(values.map(value => @date.from_ordinal(value).year()), [
2020, 2025, 2030,
])
}fn YearLocator::tick_values(self : YearLocator, first : RRuleDateTime, last : RRuleDateTime) -> Array[Double] raise DateErrorfn YearLocator::with_offset(self : YearLocator, offset_minutes : Int) -> YearLocator raise DateErrorfn auto_date_unit(lower : Double, upper : Double, count? : Int) -> Doublefn business_day_locator(weekdays? : Array[Int], holidays? : Array[DateTime], interval? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.business_day_locator(holidays=[@date.datetime(2024, 1, 1)])
let ticks = locator.tick_values(
@date.datetime(2023, 12, 29).to_ordinal(),
@date.datetime(2024, 1, 5).to_ordinal(),
)
assert_eq(@date.format_date_ticks(ticks, format="%Y-%m-%d"), [
"2023-12-29", "2024-01-02", "2024-01-03", "2024-01-04", "2024-01-05",
])
}fn concise_date_formatter(tz? : String, timezone? : DateTimeZone, formats? : Array[String], zero_formats? : Array[String], offset_formats? : Array[String], show_offset? : Bool, usetex? : Bool) -> ConciseDateFormatter raise DateErrortest {
let formatter = @date.concise_date_formatter()
let ticks = [
@date.datetime(2024, 1, 1).to_ordinal(),
@date.datetime(2024, 1, 2).to_ordinal(),
]
assert_eq(formatter.format_ticks(ticks), ["Jan", "02"])
assert_eq(formatter.get_offset(), "2024-Jan")
}fn date_formatter(format : String, tz? : String, timezone? : DateTimeZone) -> DateFormatter raise DateErrortest {
let formatter = @date.date_formatter("%H:%M %Z", tz="XST-5:45")
assert_eq(formatter.format_value(0.0), "05:45 XST")
}fn date_locator(interval? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrorfn date_tick_values(lower : Double, upper : Double, count? : Int, offset_minutes? : Int, timezone? : DateTimeZone) -> Array[Double]fn datestr2num(text : String, default_date? : DateTime, parser? : DateStringParser) -> Double raise DateErrorfn datestrs2num(texts : Array[String], default_date? : DateTime, parser? : DateStringParser) -> Array[Double] raise DateErrortest {
let value = @date.datetime(1970, 1, 1, hour=2, offset_minutes=120)
assert_eq(value.offset_minutes(), 120)
assert_eq(value.to_ordinal(), 0.0)
}fn day_locator(day? : Int, interval? : Int, bymonthday? : Array[Int], tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.day_locator(bymonthday=[1, -1])
let ticks = locator.tick_values(
@date.datetime(2024, 2, 1).to_ordinal(),
@date.datetime(2024, 2, 29).to_ordinal(),
)
assert_eq(ticks.map(value => @date.from_ordinal(value).day()), [1, 29])
}test {
let values = @date.drange(
@date.datetime(2011, 1, 1),
@date.datetime(2011, 1, 2),
@date.timedelta(hours=4),
)
assert_eq(values.length(), 6)
assert_eq(@date.num2date(values[5]).hour(), 20)
}test {
let date = @date.datetime(2021, 1, 1, hour=13)
assert_eq(
@date.format_date(date, "%G-W%V-%u %j %I %p"),
"2020-W53-5 001 01 PM",
)
}fn format_date_ticks(values : Array[Double], format? : String, offset_minutes? : Int, timezone? : DateTimeZone) -> Array[String]fn get_epoch() -> Stringfn hour_locator(hour? : Int, interval? : Int, byhour? : Array[Int], tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.hour_locator(byhour=[0, 12])
assert_eq(locator.tick_values(0.0, 1.0), [0.0, 0.5, 1.0])
}fn hour_locator_at(hour : Int, interval? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrorfn microsecond_locator(interval? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.microsecond_locator(interval=250)
let ticks = locator.tick_values(
100.0 / 86_400_000_000.0,
1000.0 / 86_400_000_000.0,
)
assert_eq(ticks.map(value => @date.from_ordinal(value).microsecond()), [
0, 250, 500, 750, 1000, 1250,
])
}fn minute_locator(minute? : Int, interval? : Int, byminute? : Array[Int], tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.minute_locator(byminute=[0, 30])
let ticks = locator.tick_values(0.0, 1.0 / 24.0)
assert_eq(ticks.map(value => @date.from_ordinal(value).minute()), [0, 30, 0])
}fn minute_locator_at(minute : Int, interval? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrorfn month_locator(interval? : Int, bymonth? : Array[Int], bymonthday? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.month_locator(bymonth=[2, 4], bymonthday=-1)
let ticks = locator.tick_values(
@date.datetime(2024, 1, 1).to_ordinal(),
@date.datetime(2024, 5, 1).to_ordinal(),
)
assert_eq(
ticks.map(value => @date.format_date(@date.from_ordinal(value), "%Y-%m-%d")),
["2024-02-29", "2024-04-30"],
)
}fn month_locator_on(month : Int, interval? : Int, bymonthday? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrorfn nth_weekday_locator(weekday? : Int, ordinal? : Int, interval? : Int, bymonth? : Array[Int], byweekday? : Array[Int], tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.nth_weekday_locator(weekday=0, ordinal=2)
let ticks = locator.tick_values(
@date.datetime(2024, 1, 1).to_ordinal(),
@date.datetime(2024, 4, 30).to_ordinal(),
)
assert_eq(
ticks.map(value => @date.format_date(@date.from_ordinal(value), "%Y-%m-%d")),
["2024-01-08", "2024-02-12", "2024-03-11", "2024-04-08"],
)
}fn num2date(value : Double, tz? : String, timezone? : DateTimeZone, offset_minutes? : Int, offset_seconds? : Int) -> DateTime raise DateErrortest {
let delta = @date.num2timedelta(1.5)
assert_eq((delta.days(), delta.seconds()), (1, 43200))
}fn rrule(frequency : RRuleFrequency, dtstart : DateTime, interval? : Int, wkst? : Int, bymonth? : Array[Int], bymonthday? : Array[Int], byyearday? : Array[Int], byweekno? : Array[Int], byeaster? : Array[Int], byweekday? : Array[Int], byhour? : Array[Int], byminute? : Array[Int], bysecond? : Array[Int], bysetpos? : Array[Int], count? : Int, until? : DateTime, cache? : Bool) -> RRule raise DateErrorfn rrule_locator(frequency : RRuleFrequency, tz? : String, timezone? : DateTimeZone, interval? : Int, wkst? : Int, bymonth? : Array[Int], bymonthday? : Array[Int], byyearday? : Array[Int], byweekno? : Array[Int], byeaster? : Array[Int], byweekday? : Array[Int], byhour? : Array[Int], byminute? : Array[Int], bysecond? : Array[Int], bysetpos? : Array[Int], dtstart? : DateTime, count? : Int, until? : DateTime) -> DateLocator raise DateErrortest {
let locator = @date.rrule_locator(
@date.Monthly,
byweekday=[0, 1, 2, 3, 4],
bysetpos=[-1],
byhour=[0],
byminute=[0],
bysecond=[0],
)
let ticks = locator.tick_values(
@date.datetime(2024, 1, 1).to_ordinal(),
@date.datetime(2024, 3, 31).to_ordinal(),
)
assert_eq(@date.format_date_ticks(ticks, format="%Y-%m-%d"), [
"2024-01-31", "2024-02-29", "2024-03-29",
])
}test {
let values = @date.rruleset().between(
@date.datetime(2024, 1, 1),
@date.datetime(2024, 1, 2),
inc=true,
)
assert_eq(values.length(), 0)
}fn second_locator(second? : Int, interval? : Int, bysecond? : Array[Int], tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.second_locator(bysecond=[0, 30])
let ticks = locator.tick_values(0.0, 1.0 / 1440.0)
assert_eq(ticks.map(value => @date.from_ordinal(value).second()), [0, 30, 0])
}fn second_locator_at(second : Int, interval? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let delta = @date.timedelta(microseconds=-1L)
assert_eq(
(delta.days(), delta.seconds(), delta.microseconds()),
(-1, 86399, 999999),
)
assert_eq(delta.total_seconds(), -0.000001)
}fn timezone(initial_offset_minutes : Int, transitions? : Array[TimeZoneTransition]) -> DateTimeZone raise DateErrortest {
let zone = try! @date.timezone(-300, transitions=[
try! @date.timezone_transition(@date.datetime(2024, 3, 10, hour=7), -240),
])
let before = try! zone.to_datetime(
@date.datetime(2024, 3, 10, hour=6, minute=59).to_ordinal(),
)
let after = try! zone.to_datetime(
@date.datetime(2024, 3, 10, hour=7).to_ordinal(),
)
assert_eq((before.hour(), before.offset_minutes()), (1, -300))
assert_eq((after.hour(), after.offset_minutes()), (3, -240))
}fn timezone_seconds(initial_offset_seconds : Int, transitions? : Array[TimeZoneTransition]) -> DateTimeZone raise DateErrortest {
let zone = @date.timezone_seconds(561, transitions=[
@date.timezone_transition_seconds(@date.datetime(1911, 3, 11), 0),
])
assert_eq(
zone.offset_seconds_at(@date.datetime(1900, 1, 1).to_ordinal()),
561,
)
}fn timezone_transition_seconds(at : DateTime, offset_seconds : Int) -> TimeZoneTransition raise DateErrorfn unregister_timezone(name : String) -> Unitfn weekday_locator(weekday? : Int, interval? : Int, byweekday? : Array[Int], tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateErrortest {
let locator = @date.weekday_locator(byweekday=[0, 2])
let ticks = locator.tick_values(
@date.datetime(2024, 1, 1).to_ordinal(),
@date.datetime(2024, 1, 7).to_ordinal(),
)
assert_eq(ticks.map(value => @date.from_ordinal(value).day()), [1, 3])
}fn year_locator(base? : Int, month? : Int, day? : Int, tz? : String, timezone? : DateTimeZone) -> DateLocator raise DateError