Ruby: How do I define a datetime field in YAML?
I'm creating test data for a Rails app. How do I defin开发者_StackOverflow中文版e the value for a datetime field in YAML?
when rails generates fixture files it uses the following format in the yaml files
one:
something_at: 2010-02-11 11:02:57
something_on: 2010-02-11
Found the answer here:
model:
datetime_field: 2010-04-16 16:32:03 -5
When I yaml DateTime, I generally pack it as a string:
foo = DateTime.now
foo_yaml = YAML.dump(foo.to_s)
foo = DateTime.parse(YAML.load(foo_yaml))
puts foo
I'd be interested to know if there's a better way.
For me works it wrapped in " "
created_at: "2010-02-11 11:02:57"
With Time zone:
created_at: 2013-09-25 16:00:00 +0800
精彩评论