From 646fdccac5f0ec506b80ed532baa4012965b682e Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 22 Jun 2024 03:40:56 +0530 Subject: Date Utils, Cosmetic and Implementation Changes * Adds Utils method for formatting date * Adds Published at to the posts page * Adds new logo, removes font dependency * Renames Posts link to Blog --- src/utils/utils.cr | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/utils/utils.cr (limited to 'src/utils') diff --git a/src/utils/utils.cr b/src/utils/utils.cr new file mode 100644 index 0000000..7b214ce --- /dev/null +++ b/src/utils/utils.cr @@ -0,0 +1,47 @@ + +def format_date(time : Time) + month = get_month(time.month) + "#{month} #{time.day}, #{time.year}" +end + +def format_date_with_time(time : Time) + month = get_month(time.month) + "#{month} #{time.day}, #{time.year} #{time.hour}:#{time.minute} #{am_or_pm(time.hour)}" +end + +def get_month(month) + case month + when 1 + "January" + when 2 + "February" + when 3 + "March" + when 4 + "April" + when 5 + "May" + when 6 + "June" + when 7 + "July" + when 8 + "August" + when 9 + "September" + when 10 + "October" + when 11 + "November" + when 12 + "December" + end +end + +def am_or_pm(hour) + if hour > 12 + "PM" + else + "AM" + end +end \ No newline at end of file -- cgit v1.2.3