========
Datetime
========

Let's setup all required adapters using zcml. This makes sure we test
the real configuration. Let's render the widgets in different
modes and try to extract the value form an request.

  >>> import datetime
  >>> import z3c.form
  >>> import zope.schema


12 o'clock
----------

Test widgets 12 o'clock PM. (12h (noon) is 12 PM wenn using AM/PM, 24h/0h is
12 AM).

  >>> field = zope.schema.Datetime(default=datetime.datetime(2007, 4, 1, 12))
  >>> widget = self.setupWidget(field)
  >>> widget.update()
  >>> widget.extract() is z3c.form.interfaces.NOVALUE
  True


INPUT_MODE
''''''''''

Render without AM/PM support:

  >>> widget.ampm = False
  >>> widget.mode == z3c.form.interfaces.INPUT_MODE
  True
  >>> print widget.render()
  <input type="text" id="foo-day" name="bar-day"
           class="datetime-widget required datetime-field"
           size="2" maxlength="2" value="1" /> /
    <select id="foo-month" name="bar-month"
            class="datetime-widget required datetime-field">
        <option value="1">January</option>
        <option value="2">February</option>
        <option value="3">March</option>
        <option value="4" selected="selected">April</option>
        <option value="5">May</option>
        <option value="6">June</option>
        <option value="7">July</option>
        <option value="8">August</option>
        <option value="9">September</option>
        <option value="10">October</option>
        <option value="11">November</option>
        <option value="12">December</option>
    </select> /
    <input type="text" id="foo-year" name="bar-year"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="4" maxlength="4"
           value="2007" /> &nbsp;
    <input type="text" id="foo-hour" name="bar-hour"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="2" maxlength="2" value="12" /> :
    <input type="text" id="foo-min" name="bar-min"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="2" maxlength="2" value="00" />
    <input name="bar-empty-marker" type="hidden" value="1" />

  >>> widget.request = self.testrequest(
  ...     form={'bar-day': '1',
  ...           'bar-month': '4',
  ...           'bar-year': '2007',
  ...           'bar-hour': '12',
  ...           'bar-min': '00',
  ...           'bar-empty-marker': '1',
  ...           }
  ...     )
  >>> widget.extract()
  ('2007', '4', '1', '12', '00')


Render with AM/PM support:

  >>> widget.ampm = True
  >>> print widget.render()
  <input type="text" id="foo-day" name="bar-day"
           class="datetime-widget required datetime-field"
           size="2" maxlength="2" value="1" /> /
    <select id="foo-month" name="bar-month"
            class="datetime-widget required datetime-field">
        <option value="1">January</option>
        <option value="2">February</option>
        <option value="3">March</option>
        <option value="4" selected="selected">April</option>
        <option value="5">May</option>
        <option value="6">June</option>
        <option value="7">July</option>
        <option value="8">August</option>
        <option value="9">September</option>
        <option value="10">October</option>
        <option value="11">November</option>
        <option value="12">December</option>
    </select> /
    <input type="text" id="foo-year" name="bar-year"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="4" maxlength="4"
           value="2007" /> &nbsp;
    <input type="text" id="foo-hour" name="bar-hour"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="2" maxlength="2" value="12" /> :
    <input type="text" id="foo-min" name="bar-min"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="2" maxlength="2" value="00" />
    <select id="foo-ampm" name="bar-ampm"
            class="datetime-widget required datetime-field">
        <option value="AM">AM</option>
        <option value="PM" selected="selected">PM</option>
    </select>
    <input name="bar-empty-marker" type="hidden" value="1" />

  >>> widget.request = self.testrequest(
  ...     form={'bar-day': '1',
  ...           'bar-month': '4',
  ...           'bar-year': '2007',
  ...           'bar-hour': '12',
  ...           'bar-min': '00',
  ...           'bar-ampm': 'PM',
  ...           'bar-empty-marker': '1',
  ...           }
  ...     )
  >>> widget.extract()
  ('2007', '4', '1', '12', '00')


DISPLAY_MODE
''''''''''''

  >>> widget.mode = z3c.form.interfaces.DISPLAY_MODE
  >>> print widget.render()
  <span id="foo"
        class="datetime-widget required datetime-field">4/1/07 12:00 PM</span>


HIDDEN_MODE
'''''''''''

  >>> widget.mode = z3c.form.interfaces.HIDDEN_MODE
  >>> print widget.render()
  <input type="hidden" id="foo" name="bar"
           class="hidden-widget" value="4/1/07 12:00 PM" />

  >>> widget.request = self.testrequest(form={'bar': '4/1/07 12:00 PM'})
  >>> widget.extract()
  ('2007', '4', '1', '12', '0')


13 o'clock
----------

Same as above, but with at 13h / 1 PM.


INPUT_MODE
''''''''''

  >>> field = zope.schema.Datetime(default=datetime.datetime(2007, 4, 1, 13))
  >>> widget = self.setupWidget(field)
  >>> widget.ampm = True
  >>> widget.update()
  >>> widget.extract() is z3c.form.interfaces.NOVALUE
  True

  >>> print widget.render()
  <input type="text" id="foo-day" name="bar-day"
           class="datetime-widget required datetime-field"
           size="2" maxlength="2" value="1" /> /
    <select id="foo-month" name="bar-month"
            class="datetime-widget required datetime-field">
        <option value="1">January</option>
        <option value="2">February</option>
        <option value="3">March</option>
        <option value="4" selected="selected">April</option>
        <option value="5">May</option>
        <option value="6">June</option>
        <option value="7">July</option>
        <option value="8">August</option>
        <option value="9">September</option>
        <option value="10">October</option>
        <option value="11">November</option>
        <option value="12">December</option>
    </select> /
    <input type="text" id="foo-year" name="bar-year"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="4" maxlength="4"
           value="2007" /> &nbsp;
    <input type="text" id="foo-hour" name="bar-hour"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="2" maxlength="2" value="01" /> :
    <input type="text" id="foo-min" name="bar-min"
           class="datetime-widget required datetime-field"
           alt="" accesskey="" size="2" maxlength="2" value="00" />
    <select id="foo-ampm" name="bar-ampm"
            class="datetime-widget required datetime-field">
        <option value="AM">AM</option>
        <option value="PM" selected="selected">PM</option>
    </select>
    <input name="bar-empty-marker" type="hidden" value="1" />

  >>> widget.request = self.testrequest(
  ...     form={'bar-day': '1',
  ...           'bar-month': '4',
  ...           'bar-year': '2007',
  ...           'bar-hour': '01',
  ...           'bar-min': '00',
  ...           'bar-ampm': 'PM',
  ...           'bar-empty-marker': '1',
  ...           }
  ...     )
  >>> widget.extract()
  ('2007', '4', '1', '13', '00') 

  >>> print widget.show_jquerytools_dateinput_js()
  <BLANKLINE>
        <input type="hidden" name="bar-calendar"
               id="foo-calendar" />
        <script type="text/javascript">
  ...
        
DISPLAY_MODE
''''''''''''

  >>> widget.mode = z3c.form.interfaces.DISPLAY_MODE
  >>> print widget.render()
  <span id="foo"
        class="datetime-widget required datetime-field">4/1/07 1:00 PM</span>


HIDDEN_MODE
'''''''''''

  >>> widget.mode = z3c.form.interfaces.HIDDEN_MODE
  >>> print widget.render()
  <input type="hidden" id="foo" name="bar"
           class="hidden-widget" value="4/1/07 1:00 PM" />

  >>> widget.request = self.testrequest(form={'bar': '4/1/07 1:00 PM'})
  >>> widget.extract()
  ('2007', '4', '1', '13', '0')
