From e2deb15925dd447c31546e5c142aa8f28a83ddcf Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 9 Jan 2019 17:41:42 +0000 Subject: [PATCH] Travis build: 936 --- README.md | 15 ++++++--------- docs/date.html | 10 +++------- test/_30s.js | 7 ++----- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d3d13e68e..e1f57ad8d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # 30 seconds of code [![License](https://img.shields.io/badge/license-CC0--1.0-blue.svg)](https://github.com/30-seconds/30-seconds-of-code/blob/master/LICENSE) [![npm Downloads](https://img.shields.io/npm/dt/30-seconds-of-code.svg)](https://www.npmjs.com/package/30-seconds-of-code) [![npm Version](https://img.shields.io/npm/v/30-seconds-of-code.svg)](https://www.npmjs.com/package/30-seconds-of-code) [![Known Vulnerabilities](https://snyk.io/test/github/30-seconds/30-seconds-of-code/badge.svg?targetFile=package.json)](https://snyk.io/test/github/30-seconds/30-seconds-of-code?targetFile=package.json)
-[![Travis Build](https://travis-ci.com/30-seconds/30-seconds-of-code.svg?branch=master)](https://travis-ci.com/30-seconds/30-seconds-of-code) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6ab7791fb1ea40b4a576d658fb96807f)](https://www.codacy.com/app/Chalarangelo/30-seconds-of-code?utm_source=github.com&utm_medium=referral&utm_content=30-seconds/30-seconds-of-code&utm_campaign=Badge_Grade) [![Maintainability](https://api.codeclimate.com/v1/badges/4b8c1e099135f2d53413/maintainability)](https://codeclimate.com/github/30-seconds/30-seconds-of-code/maintainability) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/Flet/semistandard)
+[![Travis Build](https://travis-ci.com/30-seconds/30-seconds-of-code.svg?branch=master)](https://travis-ci.com/30-seconds/30-seconds-of-code) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6ab7791fb1ea40b4a576d658fb96807f)](https://www.codacy.com/app/Chalarangelo/30-seconds-of-code?utm_source=github.com&utm_medium=referral&utm_content=30-seconds/30-seconds-of-code&utm_campaign=Badge_Grade) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/Flet/semistandard)
[![Awesome](https://awesome.re/badge.svg)](https://awesome.re) [![ProductHunt](https://img.shields.io/badge/producthunt-vote-orange.svg)](https://www.producthunt.com/posts/30-seconds-of-code) [![Gitter chat](https://img.shields.io/badge/chat-on%20gitter-4FB999.svg)](https://gitter.im/30-seconds-of-code/Lobby) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com) > Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less. @@ -4491,16 +4491,14 @@ minDate(array); // 2016-01-08T22:00:00.000Z Results in a string representation of tomorrow's date. -Use `new Date()` to get today's date, adding one day using `Date.getDate()` and `Date.setDate()`, and converting the Date object to a string. +Use `new Date()` to get the current date, increment by one using `Date.getDate()` and set the value to the result using `Date.setDate()`. +Use `Date.prototype.toISOString()` to return a string in `yyyy-mm-dd` format. ```js -const tomorrow = (long = false) => { +const tomorrow = () => { let t = new Date(); t.setDate(t.getDate() + 1); - const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( - t.getDate() - ).padStart(2, '0')}`; - return !long ? ret : `${ret}T00:00:00`; + return t.toISOString().split('T')[0]; }; ``` @@ -4508,8 +4506,7 @@ const tomorrow = (long = false) => { Examples ```js -tomorrow(); // 2017-12-27 (if current date is 2017-12-26) -tomorrow(true); // 2017-12-27T00:00:00 (if current date is 2017-12-26) +tomorrow(); // 2018-10-18 (if current date is 2018-10-18) ``` diff --git a/docs/date.html b/docs/date.html index 09a0952df..80b066572 100644 --- a/docs/date.html +++ b/docs/date.html @@ -149,14 +149,10 @@ new Date(2016, 0, 9) ]; minDate(array); // 2016-01-08T22:00:00.000Z -

tomorrow

Results in a string representation of tomorrow's date.

Use new Date() to get today's date, adding one day using Date.getDate() and Date.setDate(), and converting the Date object to a string.

const tomorrow = (long = false) => {
+

tomorrow

Results in a string representation of tomorrow's date.

Use new Date() to get the current date, increment by one using Date.getDate() and set the value to the result using Date.setDate(). Use Date.prototype.toISOString() to return a string in yyyy-mm-dd format.

const tomorrow = () => {
   let t = new Date();
   t.setDate(t.getDate() + 1);
-  const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String(
-    t.getDate()
-  ).padStart(2, '0')}`;
-  return !long ? ret : `${ret}T00:00:00`;
+  return t.toISOString().split('T')[0];
 };
-
tomorrow(); // 2017-12-27 (if current date is 2017-12-26)
-tomorrow(true); // 2017-12-27T00:00:00 (if current date is 2017-12-26)
+
tomorrow(); // 2018-10-18 (if current date is 2018-10-18)
 
\ No newline at end of file diff --git a/test/_30s.js b/test/_30s.js index be8583692..85bc2d834 100644 --- a/test/_30s.js +++ b/test/_30s.js @@ -1228,13 +1228,10 @@ const toTitleCase = str => .map(x => x.charAt(0).toUpperCase() + x.slice(1)) .join(' '); const toggleClass = (el, className) => el.classList.toggle(className); -const tomorrow = (long = false) => { +const tomorrow = () => { let t = new Date(); t.setDate(t.getDate() + 1); - const ret = `${t.getFullYear()}-${String(t.getMonth() + 1).padStart(2, '0')}-${String( - t.getDate() - ).padStart(2, '0')}`; - return !long ? ret : `${ret}T00:00:00`; + return t.toISOString().split('T')[0]; }; const transform = (obj, fn, acc) => Object.keys(obj).reduce((a, k) => fn(a, obj[k], k, obj), acc); const triggerEvent = (el, eventType, detail) =>