# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     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.


import datetime
from glyphsLib.types import parse_datetime

UFO_FORMAT = "%Y/%m/%d %H:%M:%S"


def to_ufo_time(datetime_obj):
    """Format a datetime object as specified for UFOs."""
    return datetime_obj.strftime(UFO_FORMAT)


def from_ufo_time(string):
    """Parses a datetime as specified for UFOs into a datetime object."""
    return datetime.datetime.strptime(string, UFO_FORMAT)


def from_loose_ufo_time(string):
    """Parses a datetime as specified for UFOs into a datetime object,
    or as the Glyphs formet."""
    try:
        return from_ufo_time(string)
    except ValueError:
        return parse_datetime(string)


def to_ufo_color(color):
    if isinstance(color, str):
        ret = [int(v) / 255 for v in color.split(",")]
    else:
        ret = [v / 255 for v in color]
    if len(ret) == 2:
        ret = [ret[0], ret[0], ret[0], ret[1]]
    return tuple(ret)

@@ -1288,27 +1288,29 @@
 r):%0A        
-ret
+color
  = %5Bint(v) /
@@ -1307,22 +1307,16 @@
  %5Bint(v)
- / 255
  for v i
@@ -1343,73 +1343,135 @@
     
-else:%0A        ret = %5Bv / 255 for v in
+if len(color) == 2:%0A        # Greyscale color%0A        color = (color%5B0%5D, color%5B0%5D, color%5B0%5D,
  color
-%5D
+%5B1%5D)
 %0A    
+el
 if len(
-ret
+color
 ) == 
-2
+5
 :%0A  
@@ -1480,65 +1480,125 @@
     
-ret = %5Bret%5B0%5D, ret%5B0%5D, ret%5B0%5D, ret%5B1%5D%5D%0A    return tuple(ret
+# CMYK color%0A        raise NotImplementedError(%22CMYK colors are not supported%22)%0A    return tuple(c / 255 for c in color
 )%0A

Raise an error when seeing CMYK color