Better to use `Time.parse` than `DateTime.parse` - and then you can use
`Time#round`:
Time.parse("2019-02-06T18:52:10.9986708-08:00").round
But if you're using any ORM here then you can probably just assign the time
object to your datetime attribute and the lib will store the appropriate
thing.
On Sat, Feb 9, 2019 at 4:07 PM Hillary Hueter <[email protected]> wrote:
> So i have to validate in a test that the date is being correctly written
> to the database.
>
> My Date function uses the following to get the date from an xml document
>
> DateTime.parse(@response.deep_select('TI').sort.reverse.first).strftime('%Y-%m-%d
> %H:%M:%S %z')
>
> TI will have a value like "2019-02-06T18:52:10.9986708-08:00"
>
> '%Y-%m-%d %H:%M:%S %z' is the database format.
>
> Where my test is failing is the process that writes to the database (which
> i can't update), is rounding this timestamp to the nearest second so the
> database value is 2019-02-06 18:52:11.000. So my tests are sometimes
> failing.
>
> So my question is how can i get this
> DateTime.parse(@response.deep_select('TI').sort.reverse.first).strftime('%Y-%m-%d
> %H:%M:%S %z') to include rounding to the nearest second so that my test
> will pass, since the rounding is acceptable.
>
>
>
>
>
>
>
>
>
>
> --
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
> ---
> You received this message because you are subscribed to the Google Groups
> "SD Ruby" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
---
You received this message because you are subscribed to the Google Groups "SD
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.