CH-02 : The Time Traveler’s Bug

Jai leaned back in his chair, a smug grin on his face. “Veeru, my friend, we’ve done it! The world’s first time-traveling app!” Veeru, sipping his chai, raised an eyebrow. “You sure this works? Last time, we ended up in 1975, and Gabbar stole my phone!” Jai rolled his eyes. “Relax. I’ve fixed all the bugs. Look, we just enter a date, and — “ He typed “March 30, 2025, 10:00 AM IST” into the console and pressed enter. Poof! The screen flickered. The app showed March 29, 2025, 11:30 PM. Veeru choked on his chai. “Eh? That’s yesterday! What kind of time travel is this?!” Jai’s confidence crumbled. He scanned the code, mumbling, “Must be a daylight saving issue… Oh no.” His face turned pale. “I used java.util.Date and SimpleDateFormat. The old Java date-time APIs!" Veeru blinked. “So?” Jai sighed. “They don’t handle time zones properly! The app defaulted to UTC, ignoring IST.” Veeru scratched his head. “So, how do we fix it?” Jai cracked his knuckles. “We use java.time! The modern API makes it easy." He replaced: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse("2025-03-30 10:00:00"); With: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); ZonedDateTime dateTime = LocalDateTime.parse("2025-03-30 10:00:00", formatter) .atZone(ZoneId.of("Asia/Kolkata")); Jai hit run. This time, the app correctly displayed March 30, 2025, 10:00 AM IST. Veeru cheered. “Now that’s time travel!” Jai smirked. “Lesson learned: Never mess with old Java date APIs. java.time is the future!" Veeru chuckled. “Good. Now, let’s set it to 1975 again — I have unfinished business with Gabbar!”

May 4, 2025 - 02:07
 0
CH-02 : The Time Traveler’s Bug

Jai leaned back in his chair, a smug grin on his face. “Veeru, my friend, we’ve done it! The world’s first time-traveling app!”

Veeru, sipping his chai, raised an eyebrow. “You sure this works? Last time, we ended up in 1975, and Gabbar stole my phone!”

Jai rolled his eyes. “Relax. I’ve fixed all the bugs. Look, we just enter a date, and — “ He typed “March 30, 2025, 10:00 AM IST” into the console and pressed enter.

Poof! The screen flickered. The app showed March 29, 2025, 11:30 PM.

Veeru choked on his chai. “Eh? That’s yesterday! What kind of time travel is this?!”

Jai’s confidence crumbled. He scanned the code, mumbling, “Must be a daylight saving issue… Oh no.” His face turned pale. “I used java.util.Date and SimpleDateFormat. The old Java date-time APIs!"

Veeru blinked. “So?”

Jai sighed. “They don’t handle time zones properly! The app defaulted to UTC, ignoring IST.”

Veeru scratched his head. “So, how do we fix it?”

Jai cracked his knuckles. “We use java.time! The modern API makes it easy."

He replaced:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse("2025-03-30 10:00:00");

With:

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
ZonedDateTime dateTime = LocalDateTime.parse("2025-03-30 10:00:00", formatter)
                           .atZone(ZoneId.of("Asia/Kolkata"));

Jai hit run. This time, the app correctly displayed March 30, 2025, 10:00 AM IST.

Veeru cheered. “Now that’s time travel!”

Jai smirked. “Lesson learned: Never mess with old Java date APIs. java.time is the future!"

Veeru chuckled. “Good. Now, let’s set it to 1975 again — I have unfinished business with Gabbar!”