fix: DateTime::from_iso_date

DateTimeBuilder.to_string had a faulty template str for the ISO 8601
DateTime parsing.
This commit is contained in:
Erica Marigold 2023-08-28 00:35:26 +05:30
parent 4768134e6f
commit a78ed4e122
No known key found for this signature in database
GPG key ID: 23CD97ABBBCC5ED2
3 changed files with 5 additions and 7 deletions

View file

@ -174,7 +174,6 @@ impl<'lua> FromLua<'lua> for DateTimeBuilder {
match value { match value {
LuaValue::Table(t) => Ok(Self::default() LuaValue::Table(t) => Ok(Self::default()
.with_year(t.get("year")?) .with_year(t.get("year")?)
// FIXME: Months are offset by two, months start on march for some reason...
.with_month( .with_month(
(match t.get("month")? { (match t.get("month")? {
LuaValue::String(str) => Ok(str.to_str()?.parse::<Month>().or(Err( LuaValue::String(str) => Ok(str.to_str()?.parse::<Month>().or(Err(

View file

@ -142,9 +142,11 @@ impl DateTime {
where where
T: ToString, T: ToString,
{ {
let time = let time = ChronoDateTime::parse_from_str(
ChronoDateTime::parse_from_str(iso_date.to_string().as_str(), "%Y-%m-%dT%H:%M:%SZ") format!("{}{}", iso_date.to_string(), "UTC+0000").as_str(),
.ok()?; "%Y-%m-%dT%H:%M:%SZUTC%z",
)
.ok()?;
Some(Self { Some(Self {
unix_timestamp: time.timestamp(), unix_timestamp: time.timestamp(),

View file

@ -10,7 +10,6 @@ use self::{
use crate::lune::util::TableBuilder; use crate::lune::util::TableBuilder;
// TODO: Proper error handling and stuff // TODO: Proper error handling and stuff
// FIX: DateTime::from_iso_date is broken
// FIX: fromUnixTimestamp calculation is broken // FIX: fromUnixTimestamp calculation is broken
pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> { pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
@ -104,8 +103,6 @@ impl LuaUserData for DateTime {
} }
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_method("now", |_, _this, ()| Ok(DateTime::now()));
methods.add_method("toIsoDate", |_, this, ()| Ok(this.to_iso_date())); methods.add_method("toIsoDate", |_, this, ()| Ok(this.to_iso_date()));
methods.add_method( methods.add_method(