fix current week calculation
This commit is contained in:
parent
fa8ac8c9d8
commit
ccbaa079d3
12
index.html
12
index.html
|
|
@ -1,5 +1,6 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Mappersons</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.3/dist/leaflet.css"
|
||||
|
|
@ -70,8 +71,15 @@
|
|||
<script src="jquery-ui.js"></script>
|
||||
<script>
|
||||
Date.prototype.getWeek = function () {
|
||||
var onejan = new Date(this.getFullYear(), 0, 1);
|
||||
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
|
||||
var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()));
|
||||
// Set to nearest Thursday: current date + 4 - current day number
|
||||
// Make Sunday's day number 7
|
||||
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
|
||||
// Get first day of year
|
||||
var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
||||
// Calculate full weeks to nearest Thursday
|
||||
var weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
|
||||
return weekNo
|
||||
}
|
||||
// Set initial date to current calendar week and year
|
||||
// Initialize slider with current calendar week and year
|
||||
|
|
|
|||
Loading…
Reference in a new issue