Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed convertTime. made two functions ('organizedDate' && 'clockSpl… #372

Open
wants to merge 1 commit 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
75 changes: 61 additions & 14 deletions js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,24 +374,71 @@ function getCurrentTime() {
return now.getTime();
}


function organizedDate(dateString) {
// let invalid = 'this date is invalid: '
// console.log(dateString, timeString)
let organizedArray = [];
let dateSplit = dateString.split(".")
let a = prompt('if you write date in month-day-year format - write 0. if you write date in day-month-year format - write 1')
Copy link
Collaborator

@NoamGaash NoamGaash Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

לא רלוונטי להשתמש בprompt, בייחוד לא בפונקציה כזו זניחה
אפשר להניח שהפורמט mm.dd.yyyy לא יהיה בשימוש כי אנחנו לא אמריקנים

if (/*!Date.parse(dateString)*/ a === '0') {
organizedArray[0] = dateSplit[1] //day
organizedArray[1] = dateSplit[0] //month
organizedArray[2] = dateSplit[2] //year
return organizedArray
}
else{
organizedArray[0] = dateSplit[0] //day
organizedArray[1] = dateSplit[1] //month
organizedArray[2] = dateSplit[2] //year
return organizedArray
}

}

function clockSplit(timeString){
const clockArray = timeString.split(":")
return clockArray
}




function convertTime(dateString, timeString) {
if (!dateString) dateString = startDate;
var year = dateString.substr(0, 4);
var month = dateString.substr(5, 2);
var day = dateString.substr(8, 2);
var hours = timeString.substr(0, 2);
var minutes = timeString.substr(3, 2);
var seconds = timeString.substr(6, 2);

if ($.urlParam("ff") === "true") {
realTime = new Date(year, month - 1, day, 0, hours, minutes, seconds / 60 * 1000).getTime();
} else {
realTime = new Date(year, month - 1, day, hours, minutes, seconds).getTime();
const organizeddateString = organizedDate(dateString)
const year = organizeddateString[2];
const month = organizeddateString[1];
const day = organizeddateString[0];

const organizedTime = clockSplit(timeString)
if (organizedTime.length === 2) {
const hours = organizedTime[0];
const minutes = organizedTime[1];

if ($.urlParam("ff") === "true") { // האם הפונקציה תמיד צריכה לבדוק את ff ?
var realTime = new Date(year, month - 1, day, 0, hours, minutes / 60 * 1000);
} else {
var realTime = new Date(year, month - 1, day, hours, minutes);
}

return realTime;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

לא חסר .getTime()?,

}
if (organizedTime.length === 3){
const hours = organizedTime[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

יש הרבה קוד שחוזר על עצמו
מה שאפשר להוציא מif - כדאי

const minutes = organizedTime[1];
const seconds = organizedTime[2];

if ($.urlParam("ff") === "true") {
var realTime = new Date(year, month - 1, day, 0, hours, minutes, seconds / 60 * 1000);
} else {
var realTime = new Date(year, month - 1, day, hours, minutes, seconds);
}

return realTime;
}

return realTime;
}


function containsPosition(pos, list) {
var i;
for (i = 0; i < list.length; i++) {
Expand Down