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

Time tracker for tasks #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions resources/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,55 @@ 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);
}
});

function addItem (value) {
addItemToDOM(value);
document.getElementById('item').value = '';

data.todo.push(value);
dataObjectUpdated();
// ===== < 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();

// Check if the trimmed value is not empty
if (value !== '') {
addItemToDOM(value);
document.getElementById('item').value = '';
data.todo.push(value);
dataObjectUpdated();
}
}


function renderTodoList() {
if (!data.todo.length && !data.completed.length) return;

Expand Down