✅ Phase 3 complete: DateTimeBox fully implemented and tested
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
@ -77,7 +77,7 @@ pub use string_box::StringBox;
|
|||||||
pub use integer_box::IntegerBox;
|
pub use integer_box::IntegerBox;
|
||||||
pub use bool_box::BoolBox;
|
pub use bool_box::BoolBox;
|
||||||
pub use math_box::{MathBox, FloatBox};
|
pub use math_box::{MathBox, FloatBox};
|
||||||
pub use time_box::TimeBox;
|
pub use time_box::{TimeBox, DateTimeBox};
|
||||||
pub use debug_box::DebugBox;
|
pub use debug_box::DebugBox;
|
||||||
pub use random_box::RandomBox;
|
pub use random_box::RandomBox;
|
||||||
pub use sound_box::SoundBox;
|
pub use sound_box::SoundBox;
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::ast::UnaryOperator;
|
use crate::ast::UnaryOperator;
|
||||||
use crate::boxes::{buffer::BufferBox, JSONBox, HttpClientBox, StreamBox, RegexBox, IntentBox, P2PBox};
|
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::box_trait::BoolBox;
|
||||||
use crate::operator_traits::OperatorResolver;
|
use crate::operator_traits::OperatorResolver;
|
||||||
// TODO: Fix NullBox import issue later
|
// TODO: Fix NullBox import issue later
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::boxes::{NullBox, ConsoleBox, FloatBox};
|
use crate::boxes::{NullBox, ConsoleBox, FloatBox, DateTimeBox};
|
||||||
// use crate::boxes::intent_box_wrapper::IntentBoxWrapper;
|
// use crate::boxes::intent_box_wrapper::IntentBoxWrapper;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::box_trait::StringBox;
|
use crate::box_trait::StringBox;
|
||||||
|
use crate::boxes::{TimeBox, DateTimeBox};
|
||||||
|
|
||||||
impl NyashInterpreter {
|
impl NyashInterpreter {
|
||||||
/// TimeBoxのメソッド呼び出しを実行
|
/// TimeBoxのメソッド呼び出しを実行
|
||||||
@ -171,6 +172,14 @@ impl NyashInterpreter {
|
|||||||
}
|
}
|
||||||
Ok(datetime_box.addHours(arg_values[0].clone_box()))
|
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 {
|
Err(RuntimeError::InvalidOperation {
|
||||||
message: format!("Unknown DateTimeBox method: {}", method),
|
message: format!("Unknown DateTimeBox method: {}", method),
|
||||||
|
|||||||
43
test_datetime_box.nyash
Normal file
43
test_datetime_box.nyash
Normal file
@ -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!")
|
||||||
Reference in New Issue
Block a user