Discover this podcast and so much more

Podcasts are free to enjoy without a subscription. We also offer ebooks, audiobooks, and so much more for just $11.99/month.

390: The Truth about Truthiness

390: The Truth about Truthiness

FromThe Bike Shed


390: The Truth about Truthiness

FromThe Bike Shed

ratings:
Length:
40 minutes
Released:
Jun 27, 2023
Format:
Podcast episode

Description

Joël's new work project involves tricky date formats. Stephanie has been working with former Bike Shed host Steph Viccari and loved her peer review feedback.
The concept of truthiness is tough to grasp sometimes, and JavaScript and Ruby differ in their implementation of truthiness.
Is this a problem?
Do you prefer one model over the other?
What can we learn about these design decisions?
How can we avoid common pitfalls?
[EDI](https://www.stedi.com/blog/date-and-time-in-edi](https:/www.stedi.com/blog/date-and-time-in-edi)
[Booleans don’t exist in Ruby](https://thoughtbot.com/blog/what-is-a-boolean](https://thoughtbot.com/blog/what-is-a-boolean)
[Rails valid? method](https://api.rubyonrails.org/classes/ActiveRecord/Validations.html#method-i-valid-3F](https://api.rubyonrails.org/classes/ActiveRecord/Validations.html#method-i-valid-3F)
Parse, don’t validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)
Javascript falsiness rules (https://www.sitepoint.com/javascript-truthy-falsy/)
Transcript:
STEPHANIE: Hello and welcome to another episode of The Bike Shed, a weekly podcast from your friends at thoughtbot about developing great software. I'm Stephanie Minn.
JOËL: And I'm Joël Quenneville. And together, we're here to share a little bit of what we've learned along the way.
STEPHANIE: So, Joël, what's new in your world?
JOËL: So I'm on a new project at work. And I'm doing some really interesting work where I'm connecting to a remote database third-party system directly and pulling data from that database into our system, so not via some kind of API. And one thing that's been really kind of tricky to work with are the date formats on this third-party database.
STEPHANIE: Is the date being stored in an unexpected format or something like that?
JOËL: Yes. So there's a few things that are weird with it. So this is a value that represents a point in time, and it's not stored as a date-time value. Instead, it's stored separately as a date column and a time column. So a little bit of weirdness there. We can work with it, except that the time column isn't actually a time value. It is an integer.
STEPHANIE: Oh no.
JOËL: Yeah. And if you're thinking, oh, okay, an integer, it's going to be milliseconds since midnight or something like that, which is basically how Postgres' time of day works under the hood, nope, that's not how it works. It's a positional digit thing. So, if you've got the number, you know, 1040, that means 10:40 a.m.
STEPHANIE: Oh my gosh. Is this in military time or something like that, at least?
JOËL: Yes, it is military time. But it does allow for all these, like, weird invalid values to creep in. Because, in theory, you should never go beyond 2359. But even within the hours that are allowed, let's say, between 1000 and 1100, so between 10:00 and 11:00 a.m., a clock only goes up to 59 minutes. But our base 10 number system goes up to 99, so it's possible to have 1099, which is just an invalid time.
STEPHANIE: Right. And I imagine this isn't validated or anything like that. So it is possible to store some impossible time value in this database.
JOËL: I don't know for sure if the data is validated or not, but I'm not going to trust that it is. So I have to validate it on my end.
STEPHANIE: That's fair. One thing that is striking me is what time is zero?
JOËL: So zero in military time or just 24-hour clocks in general is midnight. So 0000, 4 zeros, is midnight. What gets interesting, though, is that because it's an integer, if you put the number, you know, 0001 into the database, it's just going to store it as 1. So I can't even say, oh, the first two digits are the hours, and the second two digits are the minutes. And I'm actually dealing with, I think, seconds and then some fractional part of seconds afterwards. But I can't say that because the number of digits I have is going to be inconsistent.
So, first, I need to zero pad. Well, I have to, like, turn it into a string, zero pad the numbers so it's e
Released:
Jun 27, 2023
Format:
Podcast episode

Titles in the series (100)

On The Bike Shed, hosts Chris Toomey and Steph Viccari discuss their development experience and challenges with Ruby, Rails, JavaScript, and whatever else is drawing their attention, admiration, or ire this week.