Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3
Date and time#161
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Date and time#161
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
12 changes: 6 additions & 6 deletions1-js/05-data-types/11-date/1-new-date/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
Konstruktor `new Date`používá místní časové pásmo, takže jediná důležitá věc, kterou si musíme pamatovat, je, že měsíce se počítají od nuly. | ||
Únor má tedy číslo 1. | ||
Zde je příklad s čísly jako složkami data: | ||
```js run | ||
//new Date(rok, měsíc, den, hodiny, minuty, sekundy, milisekundy) | ||
let d1 = new Date(2012, 1, 20, 3, 12); | ||
alert( d1 ); | ||
``` | ||
Můžeme vytvořit datum i z řetězce, např. takto: | ||
```js run | ||
//new Date(řetězecSDatem) | ||
let d2 = new Date("2012-02-20T03:12"); | ||
alert( d2 ); | ||
``` |
6 changes: 3 additions & 3 deletions1-js/05-data-types/11-date/1-new-date/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions1-js/05-data-types/11-date/2-get-week-day/_js.view/solution.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
functionvraťDenVTýdnu(datum) { | ||
letdny = ['NE', 'PO', 'ÚT', 'ST', 'ČT', 'PÁ', 'SO']; | ||
returndny[datum.getDay()]; | ||
} |
30 changes: 15 additions & 15 deletions1-js/05-data-types/11-date/2-get-week-day/_js.view/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
describe("vraťDenVTýdnu", function() { | ||
it("3. leden 2014 -pátek", function() { | ||
assert.equal(vraťDenVTýdnu(new Date(2014, 0, 3)), 'PÁ'); | ||
}); | ||
it("4. leden 2014 -sobota", function() { | ||
assert.equal(vraťDenVTýdnu(new Date(2014, 0, 4)), 'SO'); | ||
}); | ||
it("5. leden 2014 -neděle", function() { | ||
assert.equal(vraťDenVTýdnu(new Date(2014, 0, 5)), 'NE'); | ||
}); | ||
it("6. leden 2014 -pondělí", function() { | ||
assert.equal(vraťDenVTýdnu(new Date(2014, 0, 6)), 'PO'); | ||
}); | ||
it("7. leden 2014 -úterý", function() { | ||
assert.equal(vraťDenVTýdnu(new Date(2014, 0, 7)), 'ÚT'); | ||
}); | ||
it("8. leden 2014 -středa", function() { | ||
assert.equal(vraťDenVTýdnu(new Date(2014, 0, 8)), 'ST'); | ||
}); | ||
it("9. leden 2014 -čtvrtek", function() { | ||
assert.equal(vraťDenVTýdnu(new Date(2014, 0, 9)), 'ČT'); | ||
}); | ||
}); |
14 changes: 7 additions & 7 deletions1-js/05-data-types/11-date/2-get-week-day/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
Metoda `datum.getDay()`vrací číslo dne v týdnu počínajíc nedělí. | ||
Vytvoříme pole dnů v týdnu, abychom mohli získat název příslušného dne podle jeho čísla: | ||
```js run demo | ||
functionvraťDenVTýdnu(datum) { | ||
letdny = ['NE', 'PO', 'ÚT', 'ST', 'ČT', 'PÁ', 'SO']; | ||
returndny[datum.getDay()]; | ||
} | ||
letdatum = new Date(2014, 0, 3); // 3. leden 2014 | ||
alert(vraťDenVTýdnu(datum) ); //PÁ | ||
``` |
10 changes: 5 additions & 5 deletions1-js/05-data-types/11-date/2-get-week-day/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions1-js/05-data-types/11-date/3-weekday/_js.view/solution.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
functionvraťMístníDenVTýdnu(datum) { | ||
letden =datum.getDay(); | ||
if (den == 0) { //0. den v týdnu (neděle) je v Evropě 7. | ||
den = 7; | ||
} | ||
returnden; | ||
} |
30 changes: 15 additions & 15 deletions1-js/05-data-types/11-date/3-weekday/_js.view/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
describe("vraťMístníDenVTýdnu vrací \"evropský\"den v týdnu", function() { | ||
it("3. leden 2014 -pátek", function() { | ||
assert.equal(vraťMístníDenVTýdnu(new Date(2014, 0, 3)), 5); | ||
}); | ||
it("4. leden 2014 -sobota", function() { | ||
assert.equal(vraťMístníDenVTýdnu(new Date(2014, 0, 4)), 6); | ||
}); | ||
it("5. leden 2014 -neděle", function() { | ||
assert.equal(vraťMístníDenVTýdnu(new Date(2014, 0, 5)), 7); | ||
}); | ||
it("6. leden 2014 -pondělí", function() { | ||
assert.equal(vraťMístníDenVTýdnu(new Date(2014, 0, 6)), 1); | ||
}); | ||
it("7. leden 2014 -úterý", function() { | ||
assert.equal(vraťMístníDenVTýdnu(new Date(2014, 0, 7)), 2); | ||
}); | ||
it("8. leden 2014 -středa", function() { | ||
assert.equal(vraťMístníDenVTýdnu(new Date(2014, 0, 8)), 3); | ||
}); | ||
it("9. leden 2014 -čtvrtek", function() { | ||
assert.equal(vraťMístníDenVTýdnu(new Date(2014, 0, 9)), 4); | ||
}); | ||
}); |
8 changes: 4 additions & 4 deletions1-js/05-data-types/11-date/3-weekday/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions1-js/05-data-types/11-date/4-get-date-ago/_js.view/solution.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
functionvraťDenPřed(datum, dny) { | ||
letkopieData = new Date(datum); | ||
kopieData.setDate(datum.getDate() -dny); | ||
returnkopieData.getDate(); | ||
} |
28 changes: 14 additions & 14 deletions1-js/05-data-types/11-date/4-get-date-ago/_js.view/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
describe("vraťDenPřed", function() { | ||
it("1den před 02.01.2015 ->den 1", function() { | ||
assert.equal(vraťDenPřed(new Date(2015, 0, 2), 1), 1); | ||
}); | ||
it("2dny před 02.01.2015 ->den 31", function() { | ||
assert.equal(vraťDenPřed(new Date(2015, 0, 2), 2), 31); | ||
}); | ||
it("100dní před 02.01.2015 ->den 24", function() { | ||
assert.equal(vraťDenPřed(new Date(2015, 0, 2), 100), 24); | ||
}); | ||
it("365dní před 02.01.2015 ->den 2", function() { | ||
assert.equal(vraťDenPřed(new Date(2015, 0, 2), 365), 2); | ||
}); | ||
it("nemění zadané datum", function() { | ||
letdatum = new Date(2015, 0, 2); | ||
letkopieData = new Date(datum); | ||
vraťDenPřed(kopieData, 100); | ||
assert.equal(datum.getTime(),kopieData.getTime()); | ||
}); | ||
}); |
28 changes: 14 additions & 14 deletions1-js/05-data-types/11-date/4-get-date-ago/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
Myšlenka je jednoduchá: odečíst zadaný počet dní od `datum`: | ||
```js | ||
functionvraťDenPřed(datum, dny) { | ||
datum.setDate(datum.getDate() -dny); | ||
returndatum.getDate(); | ||
} | ||
``` | ||
...Funkce by však neměla měnit `datum`.To je důležité, jelikož vnější kód, který nám datum předává, neočekává, že bude změněno. | ||
Abychom to implementovali, naklonujeme datum, např. takto: | ||
```js run demo | ||
functionvraťDenPřed(datum, dny) { | ||
letkopieData = new Date(datum); | ||
kopieData.setDate(datum.getDate() -dny); | ||
returnkopieData.getDate(); | ||
} | ||
letdatum = new Date(2015, 0, 2); | ||
alert(vraťDenPřed(datum, 1) ); // 1, (1. leden 2015) | ||
alert(vraťDenPřed(datum, 2) ); // 31, (31. prosinec 2014) | ||
alert(vraťDenPřed(datum, 365) ); // 2, (2. leden 2014) | ||
``` |
18 changes: 9 additions & 9 deletions1-js/05-data-types/11-date/4-get-date-ago/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions1-js/05-data-types/11-date/5-last-day-of-month/_js.view/solution.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
functionvraťPosledníDenVMěsíci(rok, měsíc) { | ||
letdatum = new Date(rok, měsíc + 1, 0); | ||
returndatum.getDate(); | ||
} |
14 changes: 7 additions & 7 deletions1-js/05-data-types/11-date/5-last-day-of-month/_js.view/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
describe("vraťPosledníDenVMěsíci", function() { | ||
it("poslední den 01.01.2012 - 31", function() { | ||
assert.equal(vraťPosledníDenVMěsíci(2012, 0), 31); | ||
}); | ||
it("poslední den01.02.2012 - 29 (přestupný rok)", function() { | ||
assert.equal(vraťPosledníDenVMěsíci(2012, 1), 29); | ||
}); | ||
it("poslední den 01.02.2013 - 28", function() { | ||
assert.equal(vraťPosledníDenVMěsíci(2013, 1), 28); | ||
}); | ||
}); |
16 changes: 8 additions & 8 deletions1-js/05-data-types/11-date/5-last-day-of-month/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
Vytvořme datum z následujícího měsíce, ale jako den předáme nulu: | ||
```js run demo | ||
functionvraťPosledníDenVMěsíci(rok, měsíc) { | ||
letdatum = new Date(rok, měsíc + 1, 0); | ||
returndatum.getDate(); | ||
} | ||
alert(vraťPosledníDenVMěsíci(2012, 0) ); // 31 | ||
alert(vraťPosledníDenVMěsíci(2012, 1) ); // 29 | ||
alert(vraťPosledníDenVMěsíci(2013, 1) ); // 28 | ||
``` | ||
Normálně dny začínají od 1,ale technicky můžeme předat jakékoli číslo a datum se samo přizpůsobí. Když tedy předáme0,bude to znamenat „jeden den před 1. dnem v měsíci“, jinými slovy: „poslední den předcházejícího měsíce“. |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.