mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
fix: DateTime::from_iso_date
DateTimeBuilder.to_string had a faulty template str for the ISO 8601 DateTime parsing.
This commit is contained in:
parent
4768134e6f
commit
a78ed4e122
3 changed files with 5 additions and 7 deletions
|
@ -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(
|
||||||
|
|
|
@ -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(),
|
||||||
|
|
|
@ -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(
|
||||||
|
|
Loading…
Add table
Reference in a new issue