RubyConf 2023 - Which Time Is It? by Joël Quenneville

Discover how to navigate the complexities of time in Ruby, including date, time, and time of day, and learn how to create custom solutions for working with time of day in your applications.

Key takeaways

Time is a Complex Concept

  • Time has different meanings in English, and it’s important to think about which type of time you’re dealing with.
  • Time of day is a simpler concept than date and time, and it’s often overlooked.

Date and Time are Not the Same

  • Date and time are two separate concepts, and they interact with each other in complex ways.
  • Date is a moment in time, while time is a duration.

Time of Day is a Specific Concept

  • Time of day refers to a specific point in time, usually between 00:00 and 23:59.
  • It’s a distinct concept from date and time, and it has its own set of rules and operations.

Math Operations on Time

  • Adding time is not as simple as adding numbers, and different operations have different meanings.
  • Subtracting time is also complex, and it depends on the resolution and the type of time involved.

Ruby’s Handling of Time

  • Ruby’s Date and Time classes are limited in their handling of time, and they don’t provide a built-in way to work with time of day.
  • Ruby’s DateTime class is more flexible, but it’s not designed for working with time of day.

Custom Solutions for Time of Day

  • To solve the problem of working with time of day, you can create your own custom class or use a gem like time-of-day.
  • This allows you to define your own operations and behaviors for working with time of day.

Importance of Understanding Time

  • Understanding time is important for solving complex problems and avoiding errors.
  • It’s a fundamental concept that can be difficult to wrap your head around, but it’s worth the effort.

Conclusion

  • Time is a complex and nuanced concept that requires careful consideration.
  • By understanding the different types of time and how they interact with each other, you can write more robust and accurate code.