I'm creating test data for a Rails app. How do I define the value for a datetime field in YAML?
YAML accepts the entire Unicode character set, except for some control characters, and may be encoded in any one of UTF-8, UTF-16 or UTF-32.
YAML (YAML Ain't Markup Language) is a data-oriented language structure used as the input format for diverse software applications. YAML is not intended to be a markup language used for document markup. An application user or administrator specifies data in a YAML file, which the application can read.
The (rather sparse) YAML FAQ recommends that you use . yaml in preference to . yml , but for historic reasons many Windows programmers are still scared of using extensions with more than three characters and so opt to use . yml instead.
YAML is a digestible data serialization language often used to create configuration files with any programming language. Designed for human interaction, YAML is a strict superset of JSON, another data serialization language. But because it's a strict superset, it can do everything that JSON can and more.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With