prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  CL-SIC parser returns wrong datetime
  CL-SIC parser returns datetime of 0018 instead of 2018, as illustrated below:
  
  `datetime: 0018-02-18 (06:43:00.000) CET`
  `production: {"unknown":0,"coal":2206.6,"hydro":2416.39660,"wind":309.314,....}`
  `updatedAt: 2018-02-20 (23:40:06.979) CET`
  
  @systemcatch any idea?
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `parsers/lib/quality.py`
  Content:
  ```
  1 import datetime
  2 import warnings
  3 
  4 import arrow
  5 
  6 
  7 class ValidationError(ValueError):
  8     pass
  9 
  10 
  11 def validate_consumption(obj, zone_key):
  12     # Data quality check
  13     if obj['consumption'] is not None and obj['consumption'] < 0:
  14         raise ValidationError('%s: consumption has negative value '
  15                               '%s' % (zone_key, obj['consumption']))
  16 
  17 
  18 def validate_exchange(item, k):
  19     if item.get('sortedZoneKeys', None) != k:
  20         raise ValidationError("Sorted country codes %s and %s don't "
  21                               "match" % (item.get('sortedZoneKeys', None), k))
  22     if 'datetime' not in item:
  23         raise ValidationError('datetime was not returned for %s' % k)
  24     if type(item['datetime']) != datetime.datetime:
  25         raise ValidationError('datetime %s is not valid for %s' %
  26                               (item['datetime'], k))
  27     data_time = arrow.get(item['datetime'])
  28     if data_time > arrow.now():
  29         raise ValidationError("Data from %s can't be in the future, data was "
  30                               "%s, now is %s" % (k, data_time, arrow.now()))
  31     if data_time.year < 2000:
  32         raise ValidationError("Data from %s can't be before year 2000, it was "
  33                               "%s" % (k, data_time))
  34 
  35 
  36 def validate_production(obj, zone_key):
  37     if 'datetime' not in obj:
  38         raise ValidationError(
  39             'datetime was not returned for %s' % zone_key)
  40     if 'countryCode' in obj:
  41         warnings.warn('object has field `countryCode`. It should have '
  42                       '`zoneKey` instead. In {}'.format(obj))
  43     if 'zoneKey' not in obj and 'countryCode' not in obj:
  44         raise ValidationError('zoneKey was not returned for %s' % zone_key)
  45     if not isinstance(obj['datetime'], datetime.datetime):
  46         raise ValidationError('datetime %s is not valid for %s' %
  47                               (obj['datetime'], zone_key))
  48     if (obj.get('zoneKey', None) or obj.get('countryCode', None)) != zone_key:
  49         raise ValidationError("Zone keys %s and %s don't match in %s" %
  50                               (obj.get('zoneKey', None), zone_key, obj))
  51     data_time = arrow.get(obj['datetime'])
  52     arrow_now = arrow.utcnow()
  53     if data_time > arrow_now:
  54         raise ValidationError(
  55             "Data from %s can't be in the future, data was %s, now is "
  56             "%s" % (zone_key, data_time, arrow_now))
  57 
  58     if ((obj.get('production', {}).get('unknown', None) is None and
  59          obj.get('production', {}).get('coal', None) is None and
  60          obj.get('production', {}).get('oil', None) is None and
  61          obj.get('production', {}).get('gas', None) is None and zone_key
  62          not in ['CH', 'NO', 'AUS-TAS', 'DK-BHM', 'US-NEISO'])):
  63         raise ValidationError(
  64             "Coal or oil or unknown production value is required for"
  65             " %s" % zone_key)
  66     for k, v in obj['production'].items():
  67         if v is None:
  68             continue
  69         if v < 0:
  70             raise ValidationError('%s: key %s has negative value %s' %
  71                                   (zone_key, k, v))
  72
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/parsers/lib/quality.py b/parsers/lib/quality.py
  --- a/parsers/lib/quality.py
  +++ b/parsers/lib/quality.py
  @@ -8,11 +8,26 @@
       pass
   
   
  +def validate_reasonable_time(item, k):
  +    data_time = arrow.get(item['datetime'])
  +    if data_time.year < 2000:
  +        raise ValidationError("Data from %s can't be before year 2000, it was "
  +                              "%s" % (k, data_time))
  +
  +    arrow_now = arrow.utcnow()
  +    if data_time > arrow_now:
  +        raise ValidationError(
  +            "Data from %s can't be in the future, data was %s, now is "
  +            "%s" % (k, data_time, arrow_now))
  +
  +
  +
   def validate_consumption(obj, zone_key):
       # Data quality check
       if obj['consumption'] is not None and obj['consumption'] < 0:
           raise ValidationError('%s: consumption has negative value '
                                 '%s' % (zone_key, obj['consumption']))
  +    validate_reasonable_time(obj, zone_key)
   
   
   def validate_exchange(item, k):
  @@ -24,13 +39,7 @@
       if type(item['datetime']) != datetime.datetime:
           raise ValidationError('datetime %s is not valid for %s' %
                                 (item['datetime'], k))
  -    data_time = arrow.get(item['datetime'])
  -    if data_time > arrow.now():
  -        raise ValidationError("Data from %s can't be in the future, data was "
  -                              "%s, now is %s" % (k, data_time, arrow.now()))
  -    if data_time.year < 2000:
  -        raise ValidationError("Data from %s can't be before year 2000, it was "
  -                              "%s" % (k, data_time))
  +    validate_reasonable_time(item, k)
   
   
   def validate_production(obj, zone_key):
  @@ -48,12 +57,6 @@
       if (obj.get('zoneKey', None) or obj.get('countryCode', None)) != zone_key:
           raise ValidationError("Zone keys %s and %s don't match in %s" %
                                 (obj.get('zoneKey', None), zone_key, obj))
  -    data_time = arrow.get(obj['datetime'])
  -    arrow_now = arrow.utcnow()
  -    if data_time > arrow_now:
  -        raise ValidationError(
  -            "Data from %s can't be in the future, data was %s, now is "
  -            "%s" % (zone_key, data_time, arrow_now))
   
       if ((obj.get('production', {}).get('unknown', None) is None and
            obj.get('production', {}).get('coal', None) is None and
  @@ -69,3 +72,4 @@
           if v < 0:
               raise ValidationError('%s: key %s has negative value %s' %
                                     (zone_key, k, v))
  +    validate_reasonable_time(obj, zone_key)
  
verification_info: {"golden_diff": "diff --git a/parsers/lib/quality.py b/parsers/lib/quality.py\n--- a/parsers/lib/quality.py\n+++ b/parsers/lib/quality.py\n@@ -8,11 +8,26 @@\n     pass\n \n \n+def validate_reasonable_time(item, k):\n+    data_time = arrow.get(item['datetime'])\n+    if data_time.year < 2000:\n+        raise ValidationError(\"Data from %s can't be before year 2000, it was \"\n+                              \"%s\" % (k, data_time))\n+\n+    arrow_now = arrow.utcnow()\n+    if data_time > arrow_now:\n+        raise ValidationError(\n+            \"Data from %s can't be in the future, data was %s, now is \"\n+            \"%s\" % (k, data_time, arrow_now))\n+\n+\n+\n def validate_consumption(obj, zone_key):\n     # Data quality check\n     if obj['consumption'] is not None and obj['consumption'] < 0:\n         raise ValidationError('%s: consumption has negative value '\n                               '%s' % (zone_key, obj['consumption']))\n+    validate_reasonable_time(obj, zone_key)\n \n \n def validate_exchange(item, k):\n@@ -24,13 +39,7 @@\n     if type(item['datetime']) != datetime.datetime:\n         raise ValidationError('datetime %s is not valid for %s' %\n                               (item['datetime'], k))\n-    data_time = arrow.get(item['datetime'])\n-    if data_time > arrow.now():\n-        raise ValidationError(\"Data from %s can't be in the future, data was \"\n-                              \"%s, now is %s\" % (k, data_time, arrow.now()))\n-    if data_time.year < 2000:\n-        raise ValidationError(\"Data from %s can't be before year 2000, it was \"\n-                              \"%s\" % (k, data_time))\n+    validate_reasonable_time(item, k)\n \n \n def validate_production(obj, zone_key):\n@@ -48,12 +57,6 @@\n     if (obj.get('zoneKey', None) or obj.get('countryCode', None)) != zone_key:\n         raise ValidationError(\"Zone keys %s and %s don't match in %s\" %\n                               (obj.get('zoneKey', None), zone_key, obj))\n-    data_time = arrow.get(obj['datetime'])\n-    arrow_now = arrow.utcnow()\n-    if data_time > arrow_now:\n-        raise ValidationError(\n-            \"Data from %s can't be in the future, data was %s, now is \"\n-            \"%s\" % (zone_key, data_time, arrow_now))\n \n     if ((obj.get('production', {}).get('unknown', None) is None and\n          obj.get('production', {}).get('coal', None) is None and\n@@ -69,3 +72,4 @@\n         if v < 0:\n             raise ValidationError('%s: key %s has negative value %s' %\n                                   (zone_key, k, v))\n+    validate_reasonable_time(obj, zone_key)\n", "issue": "CL-SIC parser returns wrong datetime\nCL-SIC parser returns datetime of 0018 instead of 2018, as illustrated below:\r\n\r\n`datetime: 0018-02-18 (06:43:00.000) CET`\r\n`production: {\"unknown\":0,\"coal\":2206.6,\"hydro\":2416.39660,\"wind\":309.314,....}`\r\n`updatedAt: 2018-02-20 (23:40:06.979) CET`\r\n\r\n@systemcatch any idea?\r\n\n", "before_files": [{"content": "import datetime\nimport warnings\n\nimport arrow\n\n\nclass ValidationError(ValueError):\n    pass\n\n\ndef validate_consumption(obj, zone_key):\n    # Data quality check\n    if obj['consumption'] is not None and obj['consumption'] < 0:\n        raise ValidationError('%s: consumption has negative value '\n                              '%s' % (zone_key, obj['consumption']))\n\n\ndef validate_exchange(item, k):\n    if item.get('sortedZoneKeys', None) != k:\n        raise ValidationError(\"Sorted country codes %s and %s don't \"\n                              \"match\" % (item.get('sortedZoneKeys', None), k))\n    if 'datetime' not in item:\n        raise ValidationError('datetime was not returned for %s' % k)\n    if type(item['datetime']) != datetime.datetime:\n        raise ValidationError('datetime %s is not valid for %s' %\n                              (item['datetime'], k))\n    data_time = arrow.get(item['datetime'])\n    if data_time > arrow.now():\n        raise ValidationError(\"Data from %s can't be in the future, data was \"\n                              \"%s, now is %s\" % (k, data_time, arrow.now()))\n    if data_time.year < 2000:\n        raise ValidationError(\"Data from %s can't be before year 2000, it was \"\n                              \"%s\" % (k, data_time))\n\n\ndef validate_production(obj, zone_key):\n    if 'datetime' not in obj:\n        raise ValidationError(\n            'datetime was not returned for %s' % zone_key)\n    if 'countryCode' in obj:\n        warnings.warn('object has field `countryCode`. It should have '\n                      '`zoneKey` instead. In {}'.format(obj))\n    if 'zoneKey' not in obj and 'countryCode' not in obj:\n        raise ValidationError('zoneKey was not returned for %s' % zone_key)\n    if not isinstance(obj['datetime'], datetime.datetime):\n        raise ValidationError('datetime %s is not valid for %s' %\n                              (obj['datetime'], zone_key))\n    if (obj.get('zoneKey', None) or obj.get('countryCode', None)) != zone_key:\n        raise ValidationError(\"Zone keys %s and %s don't match in %s\" %\n                              (obj.get('zoneKey', None), zone_key, obj))\n    data_time = arrow.get(obj['datetime'])\n    arrow_now = arrow.utcnow()\n    if data_time > arrow_now:\n        raise ValidationError(\n            \"Data from %s can't be in the future, data was %s, now is \"\n            \"%s\" % (zone_key, data_time, arrow_now))\n\n    if ((obj.get('production', {}).get('unknown', None) is None and\n         obj.get('production', {}).get('coal', None) is None and\n         obj.get('production', {}).get('oil', None) is None and\n         obj.get('production', {}).get('gas', None) is None and zone_key\n         not in ['CH', 'NO', 'AUS-TAS', 'DK-BHM', 'US-NEISO'])):\n        raise ValidationError(\n            \"Coal or oil or unknown production value is required for\"\n            \" %s\" % zone_key)\n    for k, v in obj['production'].items():\n        if v is None:\n            continue\n        if v < 0:\n            raise ValidationError('%s: key %s has negative value %s' %\n                                  (zone_key, k, v))\n", "path": "parsers/lib/quality.py"}], "after_files": [{"content": "import datetime\nimport warnings\n\nimport arrow\n\n\nclass ValidationError(ValueError):\n    pass\n\n\ndef validate_reasonable_time(item, k):\n    data_time = arrow.get(item['datetime'])\n    if data_time.year < 2000:\n        raise ValidationError(\"Data from %s can't be before year 2000, it was \"\n                              \"%s\" % (k, data_time))\n\n    arrow_now = arrow.utcnow()\n    if data_time > arrow_now:\n        raise ValidationError(\n            \"Data from %s can't be in the future, data was %s, now is \"\n            \"%s\" % (k, data_time, arrow_now))\n\n\n\ndef validate_consumption(obj, zone_key):\n    # Data quality check\n    if obj['consumption'] is not None and obj['consumption'] < 0:\n        raise ValidationError('%s: consumption has negative value '\n                              '%s' % (zone_key, obj['consumption']))\n    validate_reasonable_time(obj, zone_key)\n\n\ndef validate_exchange(item, k):\n    if item.get('sortedZoneKeys', None) != k:\n        raise ValidationError(\"Sorted country codes %s and %s don't \"\n                              \"match\" % (item.get('sortedZoneKeys', None), k))\n    if 'datetime' not in item:\n        raise ValidationError('datetime was not returned for %s' % k)\n    if type(item['datetime']) != datetime.datetime:\n        raise ValidationError('datetime %s is not valid for %s' %\n                              (item['datetime'], k))\n    validate_reasonable_time(item, k)\n\n\ndef validate_production(obj, zone_key):\n    if 'datetime' not in obj:\n        raise ValidationError(\n            'datetime was not returned for %s' % zone_key)\n    if 'countryCode' in obj:\n        warnings.warn('object has field `countryCode`. It should have '\n                      '`zoneKey` instead. In {}'.format(obj))\n    if 'zoneKey' not in obj and 'countryCode' not in obj:\n        raise ValidationError('zoneKey was not returned for %s' % zone_key)\n    if not isinstance(obj['datetime'], datetime.datetime):\n        raise ValidationError('datetime %s is not valid for %s' %\n                              (obj['datetime'], zone_key))\n    if (obj.get('zoneKey', None) or obj.get('countryCode', None)) != zone_key:\n        raise ValidationError(\"Zone keys %s and %s don't match in %s\" %\n                              (obj.get('zoneKey', None), zone_key, obj))\n\n    if ((obj.get('production', {}).get('unknown', None) is None and\n         obj.get('production', {}).get('coal', None) is None and\n         obj.get('production', {}).get('oil', None) is None and\n         obj.get('production', {}).get('gas', None) is None and zone_key\n         not in ['CH', 'NO', 'AUS-TAS', 'DK-BHM', 'US-NEISO'])):\n        raise ValidationError(\n            \"Coal or oil or unknown production value is required for\"\n            \" %s\" % zone_key)\n    for k, v in obj['production'].items():\n        if v is None:\n            continue\n        if v < 0:\n            raise ValidationError('%s: key %s has negative value %s' %\n                                  (zone_key, k, v))\n    validate_reasonable_time(obj, zone_key)\n", "path": "parsers/lib/quality.py"}]}