Skip to content

Commit

Permalink
calculator changes commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arolus committed May 15, 2024
1 parent bfbd94e commit c03763c
Show file tree
Hide file tree
Showing 32 changed files with 1,361 additions and 8,304 deletions.
1 change: 1 addition & 0 deletions assets/css/air-datepicker.min.css

Large diffs are not rendered by default.

5,812 changes: 1 addition & 5,811 deletions assets/css/main.min.css

Large diffs are not rendered by default.

Binary file modified assets/images/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/banner-1544x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/banner-772x250.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/favicon.ico
Binary file not shown.
Binary file modified assets/images/icon-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/icon-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/icon-196.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/icon-256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/icon-32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/icon-96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/icon-og.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/illustration-els.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,049 changes: 1,049 additions & 0 deletions assets/images/illustration-els.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/illustration-og.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
939 changes: 1 addition & 938 deletions assets/js/all-calculators.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,11 @@ system.forEach((i) =>
);

// SEARCH
const JSON_CALCULATORS = allCalculators;

const MODAL_SEARCH = document.querySelector('.modal-search__input')
const MODAL_SEARCH_LIST = document.querySelector('.modal-search__list')
const MODAL_SEARCH_LIST_CONTENT = document.querySelector('.modal-search__list-content')

MODAL_SEARCH.addEventListener('input', (e) => {
if(MODAL_SEARCH) MODAL_SEARCH.addEventListener('input', (e) => {
focusedElement = 0
if(e.target.value.length > 0) {
const FILTERED_JSON = JSON_CALCULATORS.filter(CALCULATOR => {
Expand Down Expand Up @@ -276,16 +274,18 @@ MODAL_SEARCH.addEventListener('input', (e) => {
// LANG
const LANG_SELECTS = document.querySelectorAll('.header-lang__select')

let langIsEng = true
if (LANG_SELECTS){
let langIsEng = true

for (const LANG_SELECT of LANG_SELECTS) {
if(LANG_SELECT.innerText !== 'ENG' && window.location.href.match(LANG_SELECT.href) !== null) {
LANG_SELECT.classList.add('header-lang__select--active')
langIsEng = false
for (const LANG_SELECT of LANG_SELECTS) {
if(LANG_SELECT.innerText !== 'ENG' && window.location.href.match(LANG_SELECT.href) !== null) {
LANG_SELECT.classList.add('header-lang__select--active')
langIsEng = false
}
}
}

if(langIsEng) LANG_SELECTS[0].classList.add('header-lang__select--active')
if(langIsEng) LANG_SELECTS[0]?.classList?.add('header-lang__select--active')
}

// SHARE
$$('.modal-share__button').forEach((button,index) => {
Expand Down
43 changes: 14 additions & 29 deletions assets/js/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,21 @@ function calculate() {
const hours = minutes / 60;
const days = Math.trunc(hours / 24);

results.unshift(plural(setCommas(days), 'd'));
results.unshift(plural(days, 'days:day:days:days:days:days'));

const holidays = getUserHolidays();

const {businessDays, weekendDays, holidayCount} =
countBusinessAndWeekendDays(dateFrom, dateTo, holidays);
results.push(plural(setCommas(businessDays), 'bd'));
results.push(plural(setCommas(weekendDays), 'wd'));
if(holidayCount) results.push(plural(setCommas(holidayCount), 'hd'));
const {weekdays, weekends, holidayCount} = countBusinessAndweekends(dateFrom, dateTo, holidays);
results.push(plural(weekdays, 'work days:work day:work days:work days:work days:work days'));
results.push(plural(weekends, 'weekend days:weekend day:weekend days:weekend days:weekend days:weekend days'));
if(holidayCount) results.push(plural(holidayCount, 'holiday days:holiday day:holiday days:holiday days:holiday days:holiday days'));

$('.result-age__text').innerHTML = '<div class="result-text">' + results.join('</div><div class="result-text"> ') + '</div>';

generateCalendar(dateFrom);
generateCalendar(dateTo, 'result-age--to');
}

function plural(number, label) {
/*Days*/
if (label === 'd') return number === 1 ? number + ' day' : number + ' days';

/*Weekend days*/
if (label === 'wd') return number === 1 ? number + ' weekend day' : number + ' weekend days';

/*Business days*/
if (label === 'bd') return number === 1 ? number + ' business day' : number + ' business days';

/*Holidays*/
if (label === 'hd') return number === 1 ? number + ' holiday' : number + ' holidays';
}

function generateCalendar(date, calendar = 'result-age--from') {
const daysInMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
let firstDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay();
Expand Down Expand Up @@ -142,14 +127,14 @@ function getUserHolidays() {
return holidays;
}

function countBusinessAndWeekendDays(startDate, endDate, holidays) {
function countBusinessAndweekends(startDate, endDate, holidays) {
// Convert the start and end dates to Date objects
startDate = new Date(startDate);
endDate = new Date(endDate);

// Initialize counters for business days and weekend days
let businessDays = 0;
let weekendDays = 0;
let weekdays = 0;
let weekends = 0;
let holidayCount = 0;

// Iterate through each day from the start date to the end date
Expand All @@ -158,14 +143,14 @@ function countBusinessAndWeekendDays(startDate, endDate, holidays) {
const dayOfWeek = startDate.getDay();
const dateString = (startDate.getMonth() + 1) + '.' + startDate.getDate();
if (dayOfWeek === 0 || dayOfWeek === 6) {
weekendDays++;
weekends++;
} else {
businessDays++;
weekdays++;
}

// Check if the current day is a holiday
if (holidays.includes(dateString)) {
businessDays--; // Subtract a business day if it's a holiday
weekdays--; // Subtract a business day if it's a holiday
holidayCount++;
}

Expand All @@ -175,13 +160,13 @@ function countBusinessAndWeekendDays(startDate, endDate, holidays) {

// If the end date is a weekend day, decrement the respective count
if (endDate.getDay() === 0 || endDate.getDay() === 6) {
weekendDays--;
weekends--;
} else {
businessDays--;
weekdays--;
}

// Return the counts
return {businessDays, weekendDays, holidayCount};
return {weekdays, weekends, holidayCount};
}

function convert() {
Expand Down
Loading

0 comments on commit c03763c

Please sign in to comment.