sebastiandaschner news


friday, october 07, 2022

Hello and welcome to newsletter #26

The previous weeks have been quite packed with workshops on containers and Kubernetes, unpacking all boxes in our new apartment, and a bit of traveling through Germany and Austria — my in-laws were visiting :)

In October and November, I’ll be at physical in-person conferences again, what still feels special after so much working from one place: Byte My Code in Krakow, Øredev in Malmö, and Java Summit-IL in Tel Aviv. I’m already looking forward to share some content on Quarkus, cloud-native, and developer productivity. And then there will be my online workshops on Quarkus development in December.

 

What’s New

 

Using Git on The Command Line

If you’ve watched me coding, you might have noticed that I spend my time either in the IDE or in the command line. As for using Git, I also almost exclusively do all commits, checkout, clones, and pulls in the command line. While this might sound tiring, with the right tips you can be more productive in such a setup than any WYSIWYG tool.

I’ve recorded a video in which I’m showing tips and tricks that help me the most effectively using Git on the command line. I’m showing how shell aliases, keyboard shortcuts, custom Git commands, and tools for GitHub can help you there.

Using Git on The Command Line

 

Video Courses on Effective Quarkus Development

If you’re interested in learning more about Quarkus and how to effectively develop and test applications, have a look at the following on-demand video courses:

These courses teach how to effectively develop Quarkus applications with quality. Besides showing how the Quarkus technologies work, I wanted to especially focus on what makes sense for real-world projects.

And in case you prefer to ask me questions interactively, I’ll be holding a similar agenda as full-day online workshops on December 12th & 13th.

 

Formatting Dates in Java

Formatting dates in java.time is rather straightforward when you can use one of the provided standard ways, for example DateTimeFormatter.ISO_LOCAL_DATE. Needless to say that we should stick to the standard ways of formatting, especially ISO-8601, but sometimes more flexibility is required.

For custom formatting you can always provide your own patterns; but what is the pattern for, let’s say printing a local date in ISO-8601, is it yyyy-MM-dd? Well, it depends.

Once you’re creating formatting patterns, it makes sense to glance at the JavaDoc of DateTimeFormatter. The y for example stands not for ‘year’ (that’s u) but for ‘year-of-era’ which will be a difference for use cases that deal with dates before year 0.

The following code demonstrates this:

LocalDate date = LocalDate.now();

System.out.println(date.format(DateTimeFormatter.ISO_LOCAL_DATE));

DateTimeFormatter pattern1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
System.out.println(pattern1.format(date));

DateTimeFormatter pattern2 = DateTimeFormatter.ofPattern("uuuu-MM-dd");
System.out.println(pattern2.format(date));

Of course, all three invocations print 2022-10-07.

But once you go back in time, the results differ:

// change line to
LocalDate date = LocalDate.now().minusYears(3500);

-1478-10-07
1479-10-07
-1478-10-07

The second format (yyyy) doesn’t print the minus prefix and refers to the year in the era (BC). In case you’re wondering, the year and era can be printed as follows:

System.out.println(DateTimeFormatter.ofPattern("yyyy G").format(date));

-> 1479 BC

So if you’re treating the year as integer number then uuuu is probably what you want, otherwise it might be advisable to print the era (BC, AD) as well.

Once more an example of read-the-documentation :)

 

Thanks a lot for reading and see you next time!

 

Did you like the content? You can subscribe to the newsletter for free: