Skip to content

Commit

Permalink
fix: duration calculation - iteration 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobgabriel committed Dec 28, 2023
1 parent f4bc510 commit c82ce56
Showing 1 changed file with 14 additions and 59 deletions.
73 changes: 14 additions & 59 deletions _includes/pro/resume/work.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,78 +15,33 @@ <h2 id="work" class="h3 hr-bottom">

{% if work.startDate.size > 0 %}
<p class="faded">
{% 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 %}
<i class="faded">not started</i>
{% 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 %}
<i class="faded"><span class="icon-history"></span> {{ yearDiff }} {{ unitYear }}, {{ monthDiff }} {{ unitMonth }}</i>
{% endif %}
{% include components/from-to.html from=work.startDate to=work.endDate format=from_to_format %}
<i class="faded"><span class="icon-history"></span> {{ yearDiff }} {{ unitYear }}, {{ monthDiff }} {{ unitMonth }}</i>
</p>
{% endif %}

Expand Down

0 comments on commit c82ce56

Please sign in to comment.