diff --git a/src/boxes/mod.rs b/src/boxes/mod.rs index e355c514..d6f57b48 100644 --- a/src/boxes/mod.rs +++ b/src/boxes/mod.rs @@ -77,7 +77,7 @@ pub use string_box::StringBox; pub use integer_box::IntegerBox; pub use bool_box::BoolBox; pub use math_box::{MathBox, FloatBox}; -pub use time_box::TimeBox; +pub use time_box::{TimeBox, DateTimeBox}; pub use debug_box::DebugBox; pub use random_box::RandomBox; pub use sound_box::SoundBox; diff --git a/src/interpreter/expressions.rs b/src/interpreter/expressions.rs index 3bc31300..1a1cdac0 100644 --- a/src/interpreter/expressions.rs +++ b/src/interpreter/expressions.rs @@ -9,7 +9,7 @@ use super::*; use crate::ast::UnaryOperator; use crate::boxes::{buffer::BufferBox, JSONBox, HttpClientBox, StreamBox, RegexBox, IntentBox, P2PBox}; -use crate::boxes::{FloatBox, MathBox, ConsoleBox, TimeBox, RandomBox, SoundBox, DebugBox, file::FileBox, MapBox}; +use crate::boxes::{FloatBox, MathBox, ConsoleBox, TimeBox, DateTimeBox, RandomBox, SoundBox, DebugBox, file::FileBox, MapBox}; use crate::box_trait::BoolBox; use crate::operator_traits::OperatorResolver; // TODO: Fix NullBox import issue later diff --git a/src/interpreter/objects.rs b/src/interpreter/objects.rs index da597b8c..e291f4be 100644 --- a/src/interpreter/objects.rs +++ b/src/interpreter/objects.rs @@ -7,7 +7,7 @@ */ use super::*; -use crate::boxes::{NullBox, ConsoleBox, FloatBox}; +use crate::boxes::{NullBox, ConsoleBox, FloatBox, DateTimeBox}; // use crate::boxes::intent_box_wrapper::IntentBoxWrapper; use std::sync::Arc; diff --git a/src/interpreter/system_methods.rs b/src/interpreter/system_methods.rs index 2848b505..403adf23 100644 --- a/src/interpreter/system_methods.rs +++ b/src/interpreter/system_methods.rs @@ -11,6 +11,7 @@ use super::*; use crate::box_trait::StringBox; +use crate::boxes::{TimeBox, DateTimeBox}; impl NyashInterpreter { /// TimeBoxのメソッド呼び出しを実行 @@ -171,6 +172,14 @@ impl NyashInterpreter { } Ok(datetime_box.addHours(arg_values[0].clone_box())) } + "toString" => { + if !arg_values.is_empty() { + return Err(RuntimeError::InvalidOperation { + message: format!("toString() expects 0 arguments, got {}", arg_values.len()), + }); + } + Ok(Box::new(datetime_box.to_string_box())) + } _ => { Err(RuntimeError::InvalidOperation { message: format!("Unknown DateTimeBox method: {}", method), diff --git a/test_datetime_box.nyash b/test_datetime_box.nyash new file mode 100644 index 00000000..4aea4aaf --- /dev/null +++ b/test_datetime_box.nyash @@ -0,0 +1,43 @@ +// test_datetime_box.nyash - DateTimeBox functionality test +// Phase 3: DateTimeBox implementation validation + +print("📅 Testing DateTimeBox implementation...") + +// Basic DateTimeBox creation +local now, timestamp_dt, parsed_dt, result + +// Test 1: Current time creation +now = new DateTimeBox() +print("Current time: " + now.toString()) + +// Test 2: Timestamp creation +timestamp_dt = new DateTimeBox(1640995200) // 2022-01-01 00:00:00 UTC +print("From timestamp: " + timestamp_dt.toString()) + +// Test 3: Date component extraction +result = now.year() +print("Current year: " + result.toString()) + +result = now.month() +print("Current month: " + result.toString()) + +result = now.day() +print("Current day: " + result.toString()) + +result = now.hour() +print("Current hour: " + result.toString()) + +result = now.minute() +print("Current minute: " + result.toString()) + +result = now.second() +print("Current second: " + result.toString()) + +// Test 4: Date arithmetic +result = now.addDays(7) +print("7 days from now: " + result.toString()) + +result = now.addHours(24) +print("24 hours from now: " + result.toString()) + +print("✅ DateTimeBox Phase 3 tests completed!") \ No newline at end of file