From c82ce56393772db95bc29bf50f303999f2487db9 Mon Sep 17 00:00:00 2001 From: jakobgabriel Date: Thu, 28 Dec 2023 21:01:13 +0100 Subject: [PATCH] fix: duration calculation - iteration 2 --- _includes/pro/resume/work.html | 73 +++++++--------------------------- 1 file changed, 14 insertions(+), 59 deletions(-) diff --git a/_includes/pro/resume/work.html b/_includes/pro/resume/work.html index ab0b2d5..c3f968c 100644 --- a/_includes/pro/resume/work.html +++ b/_includes/pro/resume/work.html @@ -15,78 +15,33 @@

{% if work.startDate.size > 0 %}

- {% assign startYear = work.startDate | date: "%Y" %} + {% assign startYear = work.startDate | date: "%Y" | plus: 0 %} {% assign startMonth = work.startDate | date: "%m" | plus: 0 %} - {% assign startDay = work.startDate | date: "%d" | plus: 0 %} - {% assign todayYear = 'now' | date: "%Y" %} + {% assign todayYear = 'now' | date: "%Y" | plus: 0 %} {% assign todayMonth = 'now' | date: "%m" | plus: 0 %} - {% assign todayDay = 'now' | date: "%d" | plus: 0 %} - {% assign endYear = work.endDate | date: "%Y" %} + {% assign endYear = work.endDate | date: "%Y" | plus: 0 %} {% assign endMonth = work.endDate | date: "%m" | plus: 0 %} - {% assign endDay = work.endDate | date: "%d" | plus: 0 %} {% if work.endDate.size == 0 %} {% assign endYear = todayYear %} {% assign endMonth = todayMonth %} - {% assign endDay = todayDay %} {% endif %} - {% assign daysInMonth = 31 %} - {% if endMonth == 4 or endMonth == 6 or endMonth == 9 or endMonth == 11 %} - {% assign daysInMonth = 30 %} - {% elsif endMonth == 2 %} - {% assign isLeapYear = endYear | modulo: 4 == 0 and (endYear | modulo: 100 != 0 or endYear | modulo: 400 == 0) %} - {% if isLeapYear %} - {% assign daysInMonth = 29 %} - {% else %} - {% assign daysInMonth = 28 %} - {% endif %} - {% endif %} + {% assign yearDiff = endYear | minus: startYear %} + {% assign monthDiff = endMonth | minus: startMonth %} - {% if endDay > daysInMonth / 2 %} - {% assign endMonth = endMonth | plus: 1 %} - {% if endMonth > 12 %} - {% assign endYear = endYear | plus: 1 %} - {% assign endMonth = 1 %} - {% endif %} + {% if monthDiff < 0 %} + {% assign yearDiff = yearDiff | minus: 1 %} + {% assign monthDiff = monthDiff | plus: 12 %} {% endif %} - {% assign startDate = startYear | append: '-' | append: startMonth | append: '-' | append: startDay %} - {% assign endDate = endYear | append: '-' | append: endMonth | append: '-' | append: endDay %} - {% assign todayDate = todayYear | append: '-' | append: todayMonth | append: '-' | append: todayDay %} - - {% if startDate > todayDate %} - not started - {% else %} - {% assign yearDiff = endYear | minus: startYear %} - {% assign monthDiff = endMonth | minus: startMonth %} - {% assign dayDiff = endDay | minus: startDay %} - - {% if monthDiff < 0 or (monthDiff == 0 and dayDiff < 0) %} - {% assign yearDiff = yearDiff | minus: 1 %} - {% assign monthDiff = monthDiff | plus: 12 %} - {% endif %} - - {% if dayDiff < 0 %} - {% assign monthDiff = monthDiff | minus: 1 %} - {% endif %} + {% assign unitYear = "year" %} + {% if yearDiff != 1 %} {% assign unitYear = "years" %} {% endif %} + {% assign unitMonth = "month" %} + {% if monthDiff != 1 %} {% assign unitMonth = "months" %} {% endif %} - {% if endDay > daysInMonth / 2 %} - {% assign monthDiff = monthDiff | plus: 1 %} - {% if monthDiff >= 12 %} - {% assign yearDiff = yearDiff | plus: 1 %} - {% assign monthDiff = 0 %} - {% endif %} - {% endif %} - - {% assign unitYear = "year" %} - {% if yearDiff != 1 %} {% assign unitYear = "years" %} {% endif %} - {% assign unitMonth = "month" %} - {% if monthDiff != 1 %} {% assign unitMonth = "months" %} {% endif %} - - {% include components/from-to.html from=work.startDate to=work.endDate format=from_to_format %} - {{ yearDiff }} {{ unitYear }}, {{ monthDiff }} {{ unitMonth }} - {% endif %} + {% include components/from-to.html from=work.startDate to=work.endDate format=from_to_format %} + {{ yearDiff }} {{ unitYear }}, {{ monthDiff }} {{ unitMonth }}

{% endif %}