Skip to content

Commit

Permalink
refactor: use constants in js date diff function
Browse files Browse the repository at this point in the history
  • Loading branch information
im-machakata committed Mar 31, 2024
1 parent f82fe33 commit 7e4ab13
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions public/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ $(function () {
$(this).find('a').removeClass('text-white');
});

// calculate date differences
$("#OutFrom, #OutTo").on('change', function () {
var toDate = $("#OutTo").val();
var fromDate = $("#OutFrom").val();
const toDate = $("#OutTo").val();
const fromDate = $("#OutFrom").val();
const toggleSubmitButton = (days) => {
$('#Submit').attr('disabled', (days == 0));
}
Expand All @@ -22,12 +23,12 @@ $(function () {
};

// Parse the input date string into a Date object
var dates = [
const dates = [
new Date(fromDate),
new Date(toDate),
];

var diffInDays = Math.floor((dates[1] - dates[0]) / (1000 * 60 * 60 * 24));
const diffInDays = Math.floor((dates[1] - dates[0]) / (1000 * 60 * 60 * 24));
toggleSubmitButton(diffInDays);
$("#Days").val(diffInDays);
});
Expand Down

0 comments on commit 7e4ab13

Please sign in to comment.