Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
task with time
Browse files Browse the repository at this point in the history
  • Loading branch information
sharma-shray committed Mar 10, 2024
1 parent bd08e24 commit 38dd64f
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions resources/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,42 @@ renderTodoList();
document.getElementById('add').addEventListener('click', function() {
var value = document.getElementById('item').value;
if (value) {
addItem(value);
addItem(value + addCompleteFullDate());
}
});

document.getElementById('item').addEventListener('keydown', function (e) {
var value = this.value;
var value = this.value + addCompleteFullDate();
if ((e.code === 'Enter' || e.code === 'NumpadEnter') && value) {
addItem(value);
}
});


// ===== < YYYY-MM-DD > ======
function addCompleteFullDate() {
var currentDate = new Date();

var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();

var formattedDate = ' [' + year + '-' + month.toString().padStart(2, '0') + '-' + day.toString().padStart(2, '0') + ']';

console.log(formattedDate);
return formattedDate;
}

// ===== < TIME ONLY > ======
function addCompleteTimeDate(){
var currentDate = new Date();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();

var formattedTime = ' [' +hours.toString().padStart(2, '0') + ':' + minutes.toString().padStart(2, '0') + ']';
return formattedTime;
}

function addItem(value) {
value = value.trim();

Expand Down

0 comments on commit 38dd64f

Please sign in to comment.