File size: 1,698 Bytes
d1ec0de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""
Simple test to understand Gradio DateTime component behavior
"""
import gradio as gr
from datetime import date, datetime

def test_datetime_component():
    """Test DateTime component creation and behavior"""
    print("Testing Gradio DateTime component...")
    
    # Test 1: Create with datetime.now()
    try:
        dt1 = gr.DateTime(
            value=datetime.now(),
            include_time=False,
            label="Test 1"
        )
        print(f"βœ“ Created DateTime with datetime.now(): {dt1.value}")
    except Exception as e:
        print(f"βœ— Failed to create DateTime with datetime.now(): {e}")
    
    # Test 2: Create with date.today()
    try:
        dt2 = gr.DateTime(
            value=date.today(),
            include_time=False,
            label="Test 2"
        )
        print(f"βœ“ Created DateTime with date.today(): {dt2.value}")
    except Exception as e:
        print(f"βœ— Failed to create DateTime with date.today(): {e}")
    
    # Test 3: Create with ISO string
    try:
        dt3 = gr.DateTime(
            value="2025-08-15",
            include_time=False,
            label="Test 3"
        )
        print(f"βœ“ Created DateTime with ISO string: {dt3.value}")
    except Exception as e:
        print(f"βœ— Failed to create DateTime with ISO string: {e}")
    
    # Test 4: Create with no value
    try:
        dt4 = gr.DateTime(
            include_time=False,
            label="Test 4"
        )
        print(f"βœ“ Created DateTime with no value: {dt4.value}")
    except Exception as e:
        print(f"βœ— Failed to create DateTime with no value: {e}")

if __name__ == "__main__":
    test_datetime_component()