def test_year_week_day(self):
     for ordinal in range(
             Date(2001, 1, 1).to_ordinal(),
             Date(2008, 1, 1).to_ordinal()):
         self.assertEqual(
             Date.from_ordinal(ordinal).iso_calendar(),
             date.fromordinal(ordinal).isocalendar())
 def test_all_positive_days_of_month_for_28_day_month(self):
     for day in range(1, 29):
         t = Date(1977, 2, day)
         self.assertEqual(t.year_month_day, (1977, 2, day))
         self.assertEqual(t.year, 1977)
         self.assertEqual(t.month, 2)
         self.assertEqual(t.day, day)
     with self.assertRaises(ValueError):
         _ = Date(1977, 2, 29)
 def test_all_positive_days_of_month_for_30_day_month(self):
     for day in range(1, 31):
         t = Date(1976, 6, day)
         self.assertEqual(t.year_month_day, (1976, 6, day))
         self.assertEqual(t.year, 1976)
         self.assertEqual(t.month, 6)
         self.assertEqual(t.day, day)
     with self.assertRaises(ValueError):
         _ = Date(1976, 6, 31)
 def test_zero_ordinal(self):
     d = Date.from_ordinal(0)
     self.assertEqual(d.year_month_day, (0, 0, 0))
     self.assertEqual(d.year, 0)
     self.assertEqual(d.month, 0)
     self.assertEqual(d.day, 0)
     self.assertIs(d, ZeroDate)
 def test_zero_date(self):
     d = Date(0, 0, 0)
     self.assertEqual(d.year_month_day, (0, 0, 0))
     self.assertEqual(d.year, 0)
     self.assertEqual(d.month, 0)
     self.assertEqual(d.day, 0)
     self.assertIs(d, ZeroDate)
def hydrate_date(days):
    """ Hydrator for `Date` values.

    :param days:
    :return: Date
    """
    return Date.from_ordinal(UNIX_EPOCH_DATE_ORDINAL + days)
Exemple #7
0
def hydrate_date(days):
    """ Hydrator for `Date` values.

    :param days:
    :return: Date
    """
    return Date.from_ordinal(get_date_unix_epoch_ordinal() + days)
 def test_instance_attributes(self):
     d = Date(2018, 4, 30)
     self.assertEqual(d.year, 2018)
     self.assertEqual(d.month, 4)
     self.assertEqual(d.day, 30)
     self.assertEqual(d.year_month_day, (2018, 4, 30))
     self.assertEqual(d.year_week_day, (2018, 18, 1))
     self.assertEqual(d.year_day, (2018, 120))
def test_date_input(cypher_eval):
    result = cypher_eval("CYPHER runtime=interpreted WITH $x AS x "
                         "RETURN [x.year, x.month, x.day]",
                         x=Date(1976, 6, 13))
    year, month, day = result
    assert year == 1976
    assert month == 6
    assert day == 13
Exemple #10
0
 def test_date(self):
     with self.driver.session() as session:
         result = session.run("CYPHER runtime=interpreted WITH $x AS x "
                              "RETURN x.year, x.month, x.day",
                              x=Date(1976, 6, 13))
         year, month, day = result.single()
         self.assertEqual(year, 1976)
         self.assertEqual(month, 6)
         self.assertEqual(day, 13)
 def test_can_retain_offset_from_end_of_month(self):
     d = Date(1976, 1, -1)
     self.assertEqual(d, Date(1976, 1, 31))
     d += Duration(months=1)
     self.assertEqual(d, Date(1976, 2, 29))
     d += Duration(months=1)
     self.assertEqual(d, Date(1976, 3, 31))
     d += Duration(months=1)
     self.assertEqual(d, Date(1976, 4, 30))
     d += Duration(months=1)
     self.assertEqual(d, Date(1976, 5, 31))
     d += Duration(months=1)
     self.assertEqual(d, Date(1976, 6, 30))
Exemple #12
0
def hydrate_datetime(seconds, nanoseconds, tz=None):
    """ Hydrator for `DateTime` and `LocalDateTime` values.

    :param seconds:
    :param nanoseconds:
    :param tz:
    :return: datetime
    """
    minutes, seconds = map(int, divmod(seconds, 60))
    hours, minutes = map(int, divmod(minutes, 60))
    days, hours = map(int, divmod(hours, 24))
    seconds = (1000000000 * seconds + nanoseconds) / 1000000000
    t = DateTime.combine(Date.from_ordinal(UNIX_EPOCH_DATE_ORDINAL + days), Time(hours, minutes, seconds))
    if tz is None:
        return t
    if isinstance(tz, int):
        tz_offset_minutes, tz_offset_seconds = divmod(tz, 60)
        zone = FixedOffset(tz_offset_minutes)
    else:
        zone = timezone(tz)
    return zone.localize(t)
def test_date_array_input(cypher_eval):
    data = [DateTime.now().date(), Date(1976, 6, 13)]
    value = cypher_eval("CREATE (a {x:$x}) RETURN a.x", x=data)
    assert value == data
def test_date_output(cypher_eval):
    value = cypher_eval("RETURN date('1976-06-13')")
    assert isinstance(value, Date)
    assert value == Date(1976, 6, 13)
def test_mixed_array_input(cypher_eval):
    data = [Date(1976, 6, 13), Duration(9, 8, 7, 6, 5, 4)]
    with pytest.raises(CypherTypeError):
        _ = cypher_eval("CREATE (a {x:$x}) RETURN a.x", x=data)
def convert_to_date(timestamp):
    dt = datetime.strptime(timestamp, '%Y-%m-%d')
    return Date(dt.year, dt.month, dt.day)
Exemple #17
0
 def test_date(self):
     with self.driver.session() as session:
         result = session.run("RETURN date('1976-06-13')")
         value = result.single().value()
         self.assertIsInstance(value, Date)
         self.assertEqual(value, Date(1976, 6, 13))
Exemple #18
0
 def test_mixed_array(self):
     with self.driver.session() as session:
         data = [Date(1976, 6, 13), Duration(9, 8, 7, 6, 5, 4)]
         with self.assertRaises(CypherTypeError):
             _ = session.write_transaction(run_and_rollback, "CREATE (a {x:$x}) RETURN a.x", x=data)
 def test_ordinal_at_start_of_1970(self):
     d = Date.from_ordinal(719163)
     self.assertEqual(d.year_month_day, (1970, 1, 1))
     self.assertEqual(d.year, 1970)
     self.assertEqual(d.month, 1)
     self.assertEqual(d.day, 1)
Exemple #20
0
def get_date_unix_epoch():
    return Date(1970, 1, 1)
 def test_format(self):
     d = Date(2018, 4, 30)
     with self.assertRaises(NotImplementedError):
         _ = d.__format__("")
 def test_ordinal_at_end_of_2017(self):
     d = Date.from_ordinal(736694)
     self.assertEqual(d.year_month_day, (2017, 12, 31))
     self.assertEqual(d.year, 2017)
     self.assertEqual(d.month, 12)
     self.assertEqual(d.day, 31)
 def test_ordinal_at_end_of_1969(self):
     d = Date.from_ordinal(719162)
     self.assertEqual(d.year_month_day, (1969, 12, 31))
     self.assertEqual(d.year, 1969)
     self.assertEqual(d.month, 12)
     self.assertEqual(d.day, 31)
 def test_from_iso_format(self):
     expected = Date(2018, 10, 1)
     actual = Date.from_iso_format("2018-10-01")
     self.assertEqual(expected, actual)
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import time, datetime, timedelta

from pytz import FixedOffset, timezone, utc

from neo4j.packstream import Structure
from neo4j.time import Duration, Date, Time, DateTime

UNIX_EPOCH_DATE = Date(1970, 1, 1)
UNIX_EPOCH_DATE_ORDINAL = UNIX_EPOCH_DATE.to_ordinal()
UNIX_EPOCH_DATETIME_UTC = DateTime(1970, 1, 1, 0, 0, 0, utc)


def hydrate_date(days):
    """ Hydrator for `Date` values.

    :param days:
    :return: Date
    """
    return Date.from_ordinal(UNIX_EPOCH_DATE_ORDINAL + days)


def dehydrate_date(value):
    """ Dehydrator for `date` values.
 def test_to_native(self):
     d = Date(2018, 10, 1)
     native = d.to_native()
     self.assertEqual(d.year, native.year)
     self.assertEqual(d.month, native.month)
     self.assertEqual(d.day, native.day)
Exemple #27
0
 def test_date_array(self):
     with self.driver.session() as session:
         data = [DateTime.now().date(), Date(1976, 6, 13)]
         value = session.write_transaction(run_and_rollback, "CREATE (a {x:$x}) RETURN a.x", x=data)
         self.assertEqual(value, data)
 def test_iso_format(self):
     d = Date(2018, 10, 1)
     self.assertEqual("2018-10-01", d.iso_format())
 def test_ordinal_at_start_of_2018(self):
     d = Date.from_ordinal(736695)
     self.assertEqual(d.year_month_day, (2018, 1, 1))
     self.assertEqual(d.year, 2018)
     self.assertEqual(d.month, 1)
     self.assertEqual(d.day, 1)
 def test_from_native(self):
     native = date(2018, 10, 1)
     d = Date.from_native(native)
     self.assertEqual(d.year, native.year)
     self.assertEqual(d.month, native.month)
     self.assertEqual(d.day, native.day)