Comparing Datetimes and Dates in Elixir
Elixir 1.15 introduced new DateTime and Date functions to compare dates.
Let’s cover the new functions, what already exists, and what to avoid at all costs!
-
New ✨:
DateTime.before?/2,DateTime.after?/2(and theirDatecounterparts) are new (since Elixir 1.15) and allow for strict comparison of datetimes (and dates), -
We’ve had
DateTime.compare/2for a while, and it returns:gt,:lt, or:eq. The nice thing aboutcompare/2is that it has equality. -
Never use
<,>,==to compare dates or datetimes! They perform structural comparisons. They don’t understand semantics.
Check out a short video of me walking through those! 👇 https://www.elixirstreams.com/tips/comparing-elixir-datetimes-and-dates
IntelliJ Elixir v15.1.0
Changelog
v15.1.0
Enhancements
- Add “Homebrew on Linux” SDK locations.
Bug Fixes
-
Replace uses of
Cell.horizontalAlign(HorizontalAlign)The API is scheduled for removal and is replaced byCall.align(AlignX.FILL). -
Ignore
group:for docs. - Don’t resolve built-in types against the index if index is updating.
-
findModuleForPsiElementinmostSpecificSdkin read action. -
Skip finding
mix.exsfor OTP apps if it can’t be read. -
Include
mix newstderr inIOExceptionfor better triage. - Highlight binary numbers and module attributes as usual in types.
-
Use
org.apache.commons.lang.SystemUtilsinstead oforg.codehaus.plexus.interpolation.os.Osto detect if on Windows for Test marker file URL. -
Call
FileIndex.getContentRootForFileinReadActionwhen getting working directory formix format. -
Don’t include
nulltarget usage types when finding usage type across all targets. - Skip bare Aliases when resolving Types.
-
Exclude
.elixir_lsdirectory when configuring newProjects. If the.elixir_lsdirectory is included the.beamit produces can interfere with normalStubIndex. - Check if Internal Erlang SDK home path exists for SDK for New Project.
-
Stop
prependingQualifiersat EEx tags.
How To Add Magic Link Login to phx.gen.auth
How to safely, simply, and securely add magic link login to your Phoenix app! phx.gen.auth provides the tools to make it quick and easy
Prefer LiveView's assert_redirect over assert_redirected
Someone in my Testing LiveView course recently asked,
When would you use
assert_redirectedinstead ofassert_redirect?
Just by looking at the helpers, you might think we want to use assert_redirected. But I always prefer using assert_redirect.
Here’s why 👇
https://www.germanvelasco.com/blog/prefer-assert-redirect-over-assert-redirected
New Elixir book: Build Your Own Web Framework in Elixir!
- Amazon Discount Code: 15ELIXIR (valid until July 31)
- Link: https://packt.link/sEaa3
Quick snippet from the “Preface”:
The goal is to demystify the aforementioned Phoenix magic by breaking it down into components and designing/building them from the ground up, all while testing their expected behaviors.
Wrote a Mix task that turns any Phoenix Site into a static site
https://github.com/lubien/single-file-phoenix-static/blob/main/lib/mix/tasks/generate_static.ex
Copy and past under lib/mix/tasks/generate_static.ex
Just released part (9/?) of my guide to LiveView for beginners.
https://dev.to/lubien/where-are-all-these-points-coming-from-758
Topics: creating models and contexts from scratch, starting with Ecto query, first glance at IEx.
Elixir's optional syntax
I always knew that Elixir had some optional syntax, but I didn’t realize how prevalent it was!
José Valim shared a new guide on Elixir’s optional syntax. And I thought it was really cool!
So, I created a short video to share an example. Hope you like it!
Timezones with TzWorld
In episode 166 we’ll build an application to fetch timezones from latitude/longitude coordinates using TzWorld.
From idea to app: The ultimate guide to digital product development
🚀 Ever wondered what it takes to transform your idea into a fully functioning digital product? 📱💡 We’re thrilled to share our latest article “From Idea to App: The Ultimate Guide to Digital Product Development.”
This comprehensive guide takes you through each stage of the product development process. Whether you’re a seasoned developer or a bright-eyed entrepreneur, you should take a look. ✨ https://curiosum.com/blog/from-idea-to-app-the-ultimate-guide-to-digital-product-development
#DigitalProductDevelopment #AppDevelopment #TechGuide #Entrepreneurship
Inspecting Elixir Dependencies at Runtime for Security
When a new vulnerability is announced, do you know exactly what is running in production? Doing this is a pretty simple one-liner, but knowing how to do it correctly is extremely important.
A Deep Dive into Mutations with Absinthe
In the third part of this series, we’ll create GraphQL mutations with Absinthe: https://blog.appsignal.com/2023/07/04/a-deep-dive-into-mutations-with-absinthe.html
Thinking Elixir 158: From Ruby to Elixir with Steve Bussey
Episode 158 of Thinking Elixir. A challenge for many people learning Elixir is the change in the mental model. Coming from OOP to Functional changes how we reason about our applications and the old way doesn’t always map over cleanly. Also, Elixir is capable of doing a lot more than other languages and frameworks can and this means learning how to build a “normal” application may change. We talk with Steve Bussey about his new book “From Ruby to Elixir” that aims to help people bridge that gap. While the title says “Ruby”, we discuss how many of the concepts apply to people coming from most OOP languages. We talk about different libraries to recommend to people coming from a traditional Rails stack and more!
To Code BEAM and back again, Stockholm, 2023
I’ve gone to every Code BEAM Stockholm I have been able to since I started Elixir. I like conferences and the reworked Erlang-focused conference has widened beautifully into a more complex mixture of Erlang, Elixir and occasionally other things. https://www.youtube.com/watch?v=D-bqAjjntfQ
Elixir’s Pinned and Non-Pinned Variables: A Deep Dive into Pattern Matching Techniques
The idea of pinned variables and variables in Elixir’s pattern matching
Open sourcing our video metrics project
These days the are great tools to measure everything that occurs in your site. Clicks, reading time, loading times, errors and so forth. And we care about the video content on our websites in the same way… right?
Lifting Your Loads for Maintainable Elixir Applications
Brian Underwood explores separating data loading from data usage in Ecto for maintainability by thinking functionally.
https://www.erlang-solutions.com/blog/lifting-your-loads-for-maintainable-elixir-applications/
Thinking Elixir 157: Adding Dialyzer Late in the Game
Episode 157 of Thinking Elixir. Dialyzer is something that eventually everyone hears about in the Elixir community. It’s a static code analysis tool that has both fans and detractors, and with good reasons on both sides! We talk with Noah Betzen about how he brought Dialyzer to several mature Elixir projects. He wanted the benefits of finding and fixing bugs and to prevent new problems from being added. He shared tools, strategies and other resources for how to get started without stopping everything to fix all the existing problems. If you’ve ever tried to add Dialyzer to a project and aborted, then this discussion may give you the courage and tools to try again!
Beginner friendly Phoenix and LiveView guide
https://dev.to/lubien/the-lazy-programmers-intro-to-liveview-chapter-1-1487 This series teaches how to use Phoenix and LiveView as we progress through the creation of a side project.
