mikeywaites / kim

Kim: A JSON Serialization and Marshaling framework
http://kim.readthedocs.org/en/latest/
Other
317 stars 17 forks source link

Support more formatting options for Datetime and Date fields #157

Closed mikeywaites closed 7 years ago

mikeywaites commented 7 years ago

The current Datetime and Date field are very simplistic. Datetime is only compatible with ISO8601 strings in both the serialization and marshaling pipeline.

Supporting a format option in both fields would make them far more flexible. Kim should not assume everyone uses iso8601 (shame on them).

class MyMapper(Mapper):
    created_at = field.DateTime()  #by default is an iso8601 formatted string and validates as such

class MyMapper(Mapper):
    created_at = field.DateTime(format='%Y-%m-%dT%H')  # pass a custom format str

The upshot of this is that Date can simple become an extension of DateTime with a formatter that only validates the provided string is '%Y-%m-%d' for example. Users could provide custom formatters to handle special use cases IE

class DateMapper(Mapper):
    year = field.Date(format='%Y')
mikeywaites commented 7 years ago

155