Skip to content

added dates calculator functions, templates and styles #274

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

Merged

Conversation

liaarbel
Copy link

@liaarbel liaarbel commented Feb 12, 2021

I created a form for two dates. One is for the first date we start from and the second is for the date we end with.
After clicking on the button "calculate" we get the difference in days between the two dates.
We don't have to enter data to the first date input, what will happen is that the first date will become the current date.

Copy link
Member

@yammesicka yammesicka left a comment

Choose a reason for hiding this comment

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

That's a great start :)

alert("Expected end date");
return;
}
var date1 = document.getElementById("startDate").value;
Copy link
Member

Choose a reason for hiding this comment

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

Use let/const

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@@ -1,21 +1,56 @@
{% extends "partials/index/index_base.html" %}

{% block content %}
<script>
Copy link
Member

Choose a reason for hiding this comment

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

Please put the JS in a different file

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@codecov-io
Copy link

codecov-io commented Feb 14, 2021

Codecov Report

Merging #274 (fd25932) into develop (b91708d) will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #274      +/-   ##
===========================================
- Coverage    95.15%   95.10%   -0.05%     
===========================================
  Files           76       76              
  Lines         3382     3352      -30     
===========================================
- Hits          3218     3188      -30     
  Misses         164      164              
Impacted Files Coverage Δ
app/routers/salary/config.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b91708d...fd25932. Read the comment docs.

<label for="endDate">End date:<em>&#x2a;</em></label>
<input id="endDate" name="date2" type="date">
</form>
<button type="button" onclick="hiddenDifference()">Calculate</button>
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use onclick - Use addEventListener instead. (We don't want to mix the logic and the view)

Copy link
Author

Choose a reason for hiding this comment

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

fixed

}
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
document.getElementById("demo").innerHTML = "The difference: " + (diffDays) + " days";
Copy link
Member

Choose a reason for hiding this comment

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

Prefer innerText

Copy link
Author

Choose a reason for hiding this comment

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

fixed

date1 = Date.now()
}
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
Copy link
Member

Choose a reason for hiding this comment

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

Save as a constant with a proper name

Copy link
Author

Choose a reason for hiding this comment

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

fixed

<input id="endDate" name="date2" type="date">
</form>
<button type="button" onclick="hiddenDifference()">Calculate</button>
<h3 id="demo"></h3>
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of the h3? Should it be a title?

If not - prefer using p/span/div tags + CSS

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 7 to 8
<div class="container mt-4">
</div>
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of this div?

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Author

Choose a reason for hiding this comment

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

It doesn't exist in the new commit

Copy link
Member

@yammesicka yammesicka Feb 17, 2021

Choose a reason for hiding this comment

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

I can't see it here. Is there a new PR or something?

Copy link
Author

Choose a reason for hiding this comment

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

Every time I pull from the develop this div exists

@@ -5,6 +5,17 @@
<div class="title">{{ day.display() }}</div>
<div class="sec-title">Location 0<sup>o</sup>c 00:00</div>
</div>
<div style="align: center">
Copy link
Member

Choose a reason for hiding this comment

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

Don't use inline styles, move them to CSS file

Copy link
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

It is still here :)

Comment on lines 7 to 8
<div class="container mt-4">
</div>
Copy link
Member

Choose a reason for hiding this comment

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

?

}
const diffDates = Math.abs(date2 - date1);
const diffInDays = Math.ceil(diffDates / (1000 * 60 * 60 * 24));
document.getElementById("demo").innerText = "The difference: " + (diffInDays) + " days";
Copy link
Member

Choose a reason for hiding this comment

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

You can use JS `Template ${strings}` if you'd like to

Copy link
Author

Choose a reason for hiding this comment

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

I took this code and I really don't know or want to change something that work pretty code :(

Copy link
Member

Choose a reason for hiding this comment

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

No problem, but we did talk about taking code from others. Please include full credit in your code.

date1 = new Date(date1);
}
else {
date1 = Date.now()
Copy link
Member

Choose a reason for hiding this comment

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

;

Copy link
Author

Choose a reason for hiding this comment

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

fixed

swal("Expected end date");
return;
}
let date1 = document.getElementById("startDate").value;
Copy link
Member

Choose a reason for hiding this comment

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

Prefer const

Copy link
Author

Choose a reason for hiding this comment

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

but date1 changing

@@ -0,0 +1,21 @@
window.onload = function () {
Copy link
Member

Choose a reason for hiding this comment

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

Prefer addEventListener on DOMContentLoaded to prevent the possibility of being overriden

Copy link
Author

Choose a reason for hiding this comment

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

I really don't understand how

}
const diffDates = Math.abs(date2 - date1);
const diffInDays = Math.ceil(diffDates / (1000 * 60 * 60 * 24));
document.getElementById("demo").innerText = "The difference: " + (diffInDays) + " days";
Copy link
Member

Choose a reason for hiding this comment

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

No problem, but we did talk about taking code from others. Please include full credit in your code.

@@ -5,6 +5,17 @@
<div class="title">{{ day.display() }}</div>
<div class="sec-title">Location 0<sup>o</sup>c 00:00</div>
</div>
<div style="align: center">
Copy link
Member

Choose a reason for hiding this comment

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

It is still here :)

Comment on lines 7 to 8
<div class="container mt-4">
</div>
Copy link
Member

@yammesicka yammesicka Feb 17, 2021

Choose a reason for hiding this comment

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

I can't see it here. Is there a new PR or something?

date1 = Date.now();
}
const diffDates = Math.abs(date2 - date1);
const diffInDays = Math.ceil(diffDates / (1000 * 60 * 60 * 24));
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe set the values to a const?

Copy link
Author

Choose a reason for hiding this comment

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

It is const

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant the numbers - 1000 * 60 * 60 * 24, extract it to another const.

Copy link
Author

@liaarbel liaarbel Feb 23, 2021

Choose a reason for hiding this comment

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

Is that what matters? It's just a formula
Here you can see the logical in the calculation

Comment on lines +1 to +3
window.addEventListener('DOMContentLoaded', (event) => {
document.getElementById("CalcBtn").addEventListener("click", hiddenDifference);
});
Copy link
Member

Choose a reason for hiding this comment

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

Great job!

@yammesicka yammesicka merged commit a8c33bc into PythonFreeCourse:develop Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants