Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with dates #57

Open
micred opened this issue Jun 24, 2016 · 2 comments
Open

Working with dates #57

micred opened this issue Jun 24, 2016 · 2 comments

Comments

@micred
Copy link

micred commented Jun 24, 2016

Hi everyone,
I am a novice of ruby-hl7 but I was wondering which is the preferred way to work with dates elements.

When saving I can set to DateTime like this:

segment.patient_dob = DateTime.now

but when reading, I get a string:

puts segment.patient_dob 
"20160624155955"

I have to manually convert from String to DateTime everytime. Is it the standard approach?

@micred
Copy link
Author

micred commented Jun 24, 2016

DateTime casting to String is also missing the time zone (%z).

@mogox
Copy link
Member

mogox commented Jul 19, 2016

To set the date we are patching Date, Time and DateTime to add the .to_hl7 method:

Time.parse('01:23').to_hl7
=> "20151202012300"
Time.now.to_hl7(3)
=> "20151202153652.302"

There is a comment on this file: https://github.com/ruby-hl7/ruby-hl7/blob/master/lib/core_ext/date_time.rb about adding a method Date.from_hl7( hl7_date ) to return a date from the hl7 format. Feel free to create a PR to solve this method, let me know if you need help with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants