Changeset 5321:fbc274119efb in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/08/13 18:42:58 (7 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add UL4 methods days(), seconds(), microseconds() and months() for timedelta/monthdelta objects.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • NEWS.rst

    r5315 r5321  
    2323*   The builtin UL4 functions are now real objects that can be passed to 
    2424    templates as arguments. 
     25 
     26*   The UL4 methods ``days``, ``seconds``, ``microseconds`` and ``months`` have 
     27    been added for ``timedelta``/``monthdelta`` objects. 
    2528 
    2629*   The UL4 functions ``vars`` and ``get`` have been removed. 
  • src/ll/ul4c.py

    r5320 r5321  
    32723272 
    32733273 
     3274@AST.makemethod 
     3275def _days(obj): 
     3276    return obj.days 
     3277 
     3278 
     3279@AST.makemethod 
     3280def _seconds(obj): 
     3281    return obj.seconds 
     3282 
     3283 
     3284@AST.makemethod 
     3285def _microseconds(obj): 
     3286    return obj.microseconds 
     3287 
     3288 
     3289@AST.makemethod 
     3290def _months(obj): 
     3291    return obj.months 
     3292 
     3293 
    32743294class TemplateClosure(Object): 
    32753295    fields = {"location", "endlocation", "name", "source", "startdelim", "enddelim", "content"} 
  • test/test_ul4.py

    r5313 r5321  
    30013001    assert '132' == r('<?print d.yearday()?>', d=datetime.date(2010, 5, 12)) 
    30023002    assert '132' == r('<?print d.yearday()?>', d=datetime.datetime(2010, 5, 12, 16, 47, 56)) 
     3003 
     3004 
     3005@pytest.mark.ul4 
     3006def test_method_days(r): 
     3007    assert '1' == r('<?print timedelta(1).days()?>') 
     3008 
     3009 
     3010@pytest.mark.ul4 
     3011def test_method_seconds(r): 
     3012    assert '42' == r('<?print timedelta(0, 42).seconds()?>') 
     3013 
     3014 
     3015@pytest.mark.ul4 
     3016def test_method_microseconds(r): 
     3017    assert '123000' == r('<?print timedelta(0, 0, 123000).microseconds()?>') 
     3018 
     3019 
     3020@pytest.mark.ul4 
     3021def test_method_months(r): 
     3022    assert '17' == r('<?print monthdelta(17).months()?>') 
    30033023 
    30043024