From 2b92a6b3e197a12abd44d126408c74fb441d878c Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 12 Aug 2021 16:46:31 +0430 Subject: [PATCH 01/31] Translate a part of article --- 1-js/05-data-types/11-date/article.md | 56 +++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index ed4e21359..9bc9973f0 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -1,75 +1,75 @@ -# Date and time +# تاریخ و زمان -Let's meet a new built-in object: [Date](mdn:js/Date). It stores the date, time and provides methods for date/time management. +بیایید یک شیء درون‌ساخت جدید را بشناسیم: [Date](mdn:js/Date). این شیء تاریخ و زمان را ذخیره می‌کند و متدهایی را برای مدیریت تاریخ/زمان فراهم می‌کند. -For instance, we can use it to store creation/modification times, to measure time, or just to print out the current date. +برای مثال، ما می‌توانیم از آن برای ذخیره‌سازی زمان ساختن/تغییردادن، اندازه‌گیری زمان یا فقط برای نمایش دادن زمان کنونی استفاده کنیم. -## Creation +## ایجاد -To create a new `Date` object call `new Date()` with one of the following arguments: +برای ایجاد یک شیء `Date` جدید باید `new Date()` را با یکی از آرگومان‌های زیر صدا بزنیم: `new Date()` -: Without arguments -- create a `Date` object for the current date and time: +: بدون آرگومان -- یک شیء `Date` برای تاریخ و زمان کنونی می‌سازد: ```js run let now = new Date(); - alert( now ); // shows current date/time + alert( now ); // تاریخ/زمان کنونی را نمایش می‌دهد ``` `new Date(milliseconds)` -: Create a `Date` object with the time equal to number of milliseconds (1/1000 of a second) passed after the Jan 1st of 1970 UTC+0. +: یک شیء `Date` با زمانی برابر با تعداد میلی‌ثانیه‌هایی (milliseconds، 1/1000 ثانیه) که از اول ژانویه سال 1970 میلادی با UTC+0 گذشته است می‌سازد. ```js run - // 0 means 01.01.1970 UTC+0 + // 01.01.1970 UTC+0 صفر یعنی let Jan01_1970 = new Date(0); alert( Jan01_1970 ); - // now add 24 hours, get 02.01.1970 UTC+0 + // 02.01.1970 UTC+0 :حالا 24 ساعت اضافه می‌کنیم و تاریخی که دریافت می‌کنیم let Jan02_1970 = new Date(24 * 3600 * 1000); alert( Jan02_1970 ); ``` - An integer number representing the number of milliseconds that has passed since the beginning of 1970 is called a *timestamp*. + عدد صحیحی که تعداد میلی‌ثانیه‌های گذشته از شروع 1970 را نمایش می‌دهد را *مُهرزمانی* می‌گویند. - It's a lightweight numeric representation of a date. We can always create a date from a timestamp using `new Date(timestamp)` and convert the existing `Date` object to a timestamp using the `date.getTime()` method (see below). + مهرزمانی یک نمایش آسان از تاریخ است. ما همیشه می‌توانیم با استفاده از `new Date(timestamp)` یک تاریخ را از یک مهرزمانی بسازیم و شیء `Date` موجود را با استفاده از متد `date.getTime()` به مهرزمانی تبدیل کنیم (ادامه متن را ببینید). - Dates before 01.01.1970 have negative timestamps, e.g.: + :تاریخ‌های قبل از 01.01.1970 مهرزمانی منفی دارند، برای مثال ```js run - // 31 Dec 1969 + // سی و یک دسامبر 1969 let Dec31_1969 = new Date(-24 * 3600 * 1000); alert( Dec31_1969 ); ``` `new Date(datestring)` -: If there is a single argument, and it's a string, then it is parsed automatically. The algorithm is the same as `Date.parse` uses, we'll cover it later. +: اگر یک آرگومان تنها وجود داشته باشد که رشته است، سپس به طور خودکار تجزیه می‌شود. الگوریتم آن با `Date.parse` یکسان است، ما آن را بعدا یاد می‌گیریم. ```js run let date = new Date("2017-01-26"); alert(date); - // The time is not set, so it's assumed to be midnight GMT and - // is adjusted according to the timezone the code is run in - // So the result could be + // باشد GMT زمان تنظیم نشده است پس فرض می‌شود که نیمه شب + // و با توجه به منطقه‌زمانی‌ای که کد در آن اجرا می‌شود تنظیم می‌شود + // :پس نتیجه می‌تواند این باشد // Thu Jan 26 2017 11:00:00 GMT+1100 (Australian Eastern Daylight Time) - // or + // یا // Wed Jan 25 2017 16:00:00 GMT-0800 (Pacific Standard Time) ``` `new Date(year, month, date, hours, minutes, seconds, ms)` -: Create the date with the given components in the local time zone. Only the first two arguments are obligatory. +: یک تاریخ با مؤلفه‎های داده شده در منطقه‌زمانی محلی می‌سازد. فقط دو آرگومان اول ضروری هستند. - - The `year` must have 4 digits: `2013` is okay, `98` is not. - - The `month` count starts with `0` (Jan), up to `11` (Dec). - - The `date` parameter is actually the day of month, if absent then `1` is assumed. - - If `hours/minutes/seconds/ms` is absent, they are assumed to be equal `0`. + - پارامتر `year` باشد حتما 4 رقم باشد: `2013` خوب است ولی `98` نه. + - شمارش پارامتر `month` از `0` (ژانویه) تا `11` (دسامبر) است. + - پارامتر `date` در واقع روز ماه است، اگر وارد نشود `1` فرض می‌شود. + - اگر `hours/minutes/seconds/ms` وارد نشوند،برای آنها `0` در نظر گرفته می‌شود. - For instance: + برای مثال: ```js - new Date(2011, 0, 1, 0, 0, 0, 0); // 1 Jan 2011, 00:00:00 - new Date(2011, 0, 1); // the same, hours etc are 0 by default + new Date(2011, 0, 1, 0, 0, 0, 0); // اول ژانویه 2011، ساعت 00:00:00 + new Date(2011, 0, 1); // یکسان است، ساعت و بقیه پارامترها به طور پیش‌فرض 0 هستند ``` - The maximal precision is 1 ms (1/1000 sec): + :بیشترین دقت 1 میلی‌ثانیه (1/1000 ثانیه) است ```js run let date = new Date(2011, 0, 1, 2, 3, 4, 567); From 9a92e61b2aa969a37bdadd6e0fdf02a7423ea825 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 13 Aug 2021 14:52:39 +0430 Subject: [PATCH 02/31] Translate a part of article --- 1-js/05-data-types/11-date/article.md | 44 +++++++++++++-------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 9bc9973f0..3fbd31eff 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -76,59 +76,59 @@ alert( date ); // 1.01.2011, 02:03:04.567 ``` -## Access date components +## دسترسی به اجزاء تاریخ -There are methods to access the year, month and so on from the `Date` object: +متدهایی برای دسترسی به سال، ماه و بقیه اجزاء در شیء `Date` وجود دارد: [getFullYear()](mdn:js/Date/getFullYear) -: Get the year (4 digits) +: دریافت سال (4 رقم) [getMonth()](mdn:js/Date/getMonth) -: Get the month, **from 0 to 11**. +: دریافت ماه، **از 0 تا 11**. [getDate()](mdn:js/Date/getDate) -: Get the day of month, from 1 to 31, the name of the method does look a little bit strange. +: دریافت روز ماه، از 1 تا 31، اسم متد واقعا کمی عجیب بنظر می‌رسد. -[getHours()](mdn:js/Date/getHours), [getMinutes()](mdn:js/Date/getMinutes), [getSeconds()](mdn:js/Date/getSeconds), [getMilliseconds()](mdn:js/Date/getMilliseconds) -: Get the corresponding time components. +[getHours()](mdn:js/Date/getHours)، [getMinutes()](mdn:js/Date/getMinutes)، [getSeconds()](mdn:js/Date/getSeconds)، [getMilliseconds()](mdn:js/Date/getMilliseconds) +: جزء متناظر با خود را دریافت می‌کنند یعنی به ترتیب: ساعت، دقیقه، ثانیه و میلی‌ثانیه. -```warn header="Not `getYear()`, but `getFullYear()`" -Many JavaScript engines implement a non-standard method `getYear()`. This method is deprecated. It returns 2-digit year sometimes. Please never use it. There is `getFullYear()` for the year. +```warn header="متد `getYear()` درست نیست بلکه `getFullYear()` درست است" +بسیاری از موتورهای جاوااسکریپت یک متد غیر استاندارد `getYear()` را پیاده‌سازی می‌کنند. این متد منسوخ شده است. بعضی اوقات یک سال 2 رقمی را برمی‌گرداند. لطفا هیچ‌وقت از آن استفاده نکنید. متد `getFullYear()` برای سال وجود دارد. ``` -Additionally, we can get a day of week: +علاوه بر این، ما می‌توانیم روز هفته را هم دریافت کنیم: [getDay()](mdn:js/Date/getDay) -: Get the day of week, from `0` (Sunday) to `6` (Saturday). The first day is always Sunday, in some countries that's not so, but can't be changed. +: دریافت روز هفته، از `0` (Sunday، یکشنبه) تا `6` (Saturday، شنبه). اولین روز همیشه Sunday (یکشنبه) است و در بعضی از کشورها اینگونه نیست اما نمی‌توان آن را تغییر داد. -**All the methods above return the components relative to the local time zone.** +**تمام متدهای بالا اجزاء را با توجه به منطقه زمانی محلی برمی‌گردانند.** -There are also their UTC-counterparts, that return day, month, year and so on for the time zone UTC+0: [getUTCFullYear()](mdn:js/Date/getUTCFullYear), [getUTCMonth()](mdn:js/Date/getUTCMonth), [getUTCDay()](mdn:js/Date/getUTCDay). Just insert the `"UTC"` right after `"get"`. +همچنین نقطه مقابل آنها در UTC هم وجود دارد که روز، ماه، سال و بقیه را برای منطقه زمانی UTC+0 برمی‌گرداند: [getUTCFullYear()](mdn:js/Date/getUTCFullYear)، [getUTCMonth()](mdn:js/Date/getUTCMonth)، [getUTCDay()](mdn:js/Date/getUTCDay). فقط `"UTC"` را بعد از `"get"` اضافه کنید. -If your local time zone is shifted relative to UTC, then the code below shows different hours: +اگر منطقه زمانی شما نسبت به UTC متفاوت باشد، کد پایین ساعت‌های متفاوت را نشان می‌دهد: ```js run -// current date +// تاریخ کنونی let date = new Date(); -// the hour in your current time zone +// ساعت در منطقه زمانی کنونی شما alert( date.getHours() ); -// the hour in UTC+0 time zone (London time without daylight savings) +// (زمان شهر لندن بدون ساعت تابستانی) UTC+0 ساعت در منطقه زمانی alert( date.getUTCHours() ); ``` -Besides the given methods, there are two special ones that do not have a UTC-variant: +علاوه بر متدهای داده شده، دو متد خاص هم وجود دارند که نوع UTC برای آنها وجود ندارد: [getTime()](mdn:js/Date/getTime) -: Returns the timestamp for the date -- a number of milliseconds passed from the January 1st of 1970 UTC+0. +: مهرزمانی را برای تاریخ برمی‌گرداند -- عددی برابر با میلی‌ثانیه‌هایی که از اول ژانویه 1970 میلادی با UTC+0 گذشته است. [getTimezoneOffset()](mdn:js/Date/getTimezoneOffset) -: Returns the difference between UTC and the local time zone, in minutes: +: تقاوت بین UTC و منطقه زمانی محلی را به دقیقه برمی‌گرداند. ```js run - // if you are in timezone UTC-1, outputs 60 - // if you are in timezone UTC+3, outputs -180 + // باشید، خروجی 60 می‌دهد UTC-1 اگر شما در منطقه زمانی + // باشید، خروجی 180- می‌دهد UTC+3 اگر در منطقه زمانی alert( new Date().getTimezoneOffset() ); ``` From ad3968e2c63dfd2ec501fdc0614c02e4b83fba7f Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 13 Aug 2021 14:56:33 +0430 Subject: [PATCH 03/31] Add English term --- 1-js/05-data-types/11-date/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 3fbd31eff..841833525 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -29,7 +29,7 @@ alert( Jan02_1970 ); ``` - عدد صحیحی که تعداد میلی‌ثانیه‌های گذشته از شروع 1970 را نمایش می‌دهد را *مُهرزمانی* می‌گویند. + عدد صحیحی که تعداد میلی‌ثانیه‌های گذشته از شروع 1970 را نمایش می‌دهد را *مُهرزمانی (timestamp)* می‌گویند. مهرزمانی یک نمایش آسان از تاریخ است. ما همیشه می‌توانیم با استفاده از `new Date(timestamp)` یک تاریخ را از یک مهرزمانی بسازیم و شیء `Date` موجود را با استفاده از متد `date.getTime()` به مهرزمانی تبدیل کنیم (ادامه متن را ببینید). From 87837a5726dbc5acd04f9d6e004ddc2cb34d5a75 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sat, 14 Aug 2021 15:27:46 +0430 Subject: [PATCH 04/31] Translate a part of article --- 1-js/05-data-types/11-date/article.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 841833525..54fd86879 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -133,9 +133,9 @@ alert( date.getUTCHours() ); ``` -## Setting date components +## تنظیم کردن اجزاء تاریخ -The following methods allow to set date/time components: +متدهای زیر به اجازه تنظیم کردن اجزاء تاریخ را می‌دهند: - [`setFullYear(year, [month], [date])`](mdn:js/Date/setFullYear) - [`setMonth(month, [date])`](mdn:js/Date/setMonth) @@ -144,22 +144,21 @@ The following methods allow to set date/time components: - [`setMinutes(min, [sec], [ms])`](mdn:js/Date/setMinutes) - [`setSeconds(sec, [ms])`](mdn:js/Date/setSeconds) - [`setMilliseconds(ms)`](mdn:js/Date/setMilliseconds) -- [`setTime(milliseconds)`](mdn:js/Date/setTime) (sets the whole date by milliseconds since 01.01.1970 UTC) +- [`setTime(milliseconds)`](mdn:js/Date/setTime) (تمام تاریخ را توسط میلی‌ثانیه‌های گذشته از 01.01.1970 UTC+0 تنظیم می‌کند) -Every one of them except `setTime()` has a UTC-variant, for instance: `setUTCHours()`. +تمام آنها به جز `setTime()` یک نوع UTC دارند، برای مثال: `setUTCHours()`. -As we can see, some methods can set multiple components at once, for example `setHours`. The components that are not mentioned are not modified. +همانطور که می‌بینیم، بعضی از متدها می‌توانند چند جزء را همزمان تنظیم کنند، برای مثال `setHours`. اجزائی که ذکر نشوند تغییر داده نمی‌شوند. -For instance: +برای مثال: ```js run let today = new Date(); today.setHours(0); -alert(today); // still today, but the hour is changed to 0 - +alert(today); // .هنوز امروز است اما ساعت به 0 تغییر داده شد today.setHours(0, 0, 0, 0); -alert(today); // still today, now 00:00:00 sharp. +alert(today); // .هنوز هم امروز است، الان ساعت دقیقا 00:00:00 است ``` ## Autocorrection From da70de4c0648314ad13c6f4a2c9260f1c4d0ff3b Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sat, 14 Aug 2021 15:31:13 +0430 Subject: [PATCH 05/31] Typo --- 1-js/05-data-types/11-date/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 54fd86879..4d1d32b44 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -57,7 +57,7 @@ `new Date(year, month, date, hours, minutes, seconds, ms)` : یک تاریخ با مؤلفه‎های داده شده در منطقه‌زمانی محلی می‌سازد. فقط دو آرگومان اول ضروری هستند. - - پارامتر `year` باشد حتما 4 رقم باشد: `2013` خوب است ولی `98` نه. + - پارامتر `year` باید حتما 4 رقم باشد: `2013` خوب است ولی `98` نه. - شمارش پارامتر `month` از `0` (ژانویه) تا `11` (دسامبر) است. - پارامتر `date` در واقع روز ماه است، اگر وارد نشود `1` فرض می‌شود. - اگر `hours/minutes/seconds/ms` وارد نشوند،برای آنها `0` در نظر گرفته می‌شود. From 545d065213e9721e6bad360b18fa6461ae6b7ba8 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sat, 14 Aug 2021 15:33:54 +0430 Subject: [PATCH 06/31] Add a missing pronoun --- 1-js/05-data-types/11-date/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 4d1d32b44..88e6acd6b 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -135,7 +135,7 @@ alert( date.getUTCHours() ); ## تنظیم کردن اجزاء تاریخ -متدهای زیر به اجازه تنظیم کردن اجزاء تاریخ را می‌دهند: +متدهای زیر به ما اجازه تنظیم کردن اجزاء تاریخ را می‌دهند: - [`setFullYear(year, [month], [date])`](mdn:js/Date/setFullYear) - [`setMonth(month, [date])`](mdn:js/Date/setMonth) From c7d40b14d79e6b2656b9f954235624a86ca9c184 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 15 Aug 2021 16:39:32 +0430 Subject: [PATCH 07/31] Translate a part of article --- 1-js/05-data-types/11-date/article.md | 46 +++++++++++++-------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 88e6acd6b..2f869e6ad 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -161,20 +161,20 @@ today.setHours(0, 0, 0, 0); alert(today); // .هنوز هم امروز است، الان ساعت دقیقا 00:00:00 است ``` -## Autocorrection +## تصحیح خودکار -The *autocorrection* is a very handy feature of `Date` objects. We can set out-of-range values, and it will auto-adjust itself. +*تصحیح خودکار* یک خاصیت بسیار کاربردی شیءهای `Date` است. ما می‌توانیم مقدارهای خارج از محدوده را قرار دهیم و شیء `Date` به طور خودکار خودش را تنظیم می‌کند. -For instance: +برای مثال: ```js run let date = new Date(2013, 0, *!*32*/!*); // 32 Jan 2013 ?!? -alert(date); // ...is 1st Feb 2013! +alert(date); // !برابر است با اول فوریه 2013... ``` -Out-of-range date components are distributed automatically. +اجزاء خارج از محدوده تاریخ به طور خودکار توزیع می‌شوند. -Let's say we need to increase the date "28 Feb 2016" by 2 days. It may be "2 Mar" or "1 Mar" in case of a leap-year. We don't need to think about it. Just add 2 days. The `Date` object will do the rest: +بیایید فرض کنیم که ما نیاز داریم تاریخ «28 فوریه 2016» را دو روز به جلو ببریم. ممکن است برابر با «دوم مارس» یا اگر سال کبیسه باشد «اول مارس» شود. ما نیازی نداریم که به آن فکر کنیم. فقط 2 روز به آن اضافه کنید. شیء `Date` بقیه کار را انجام می‌دهد: ```js run let date = new Date(2016, 1, 28); @@ -182,54 +182,54 @@ let date = new Date(2016, 1, 28); date.setDate(date.getDate() + 2); */!* -alert( date ); // 1 Mar 2016 +alert( date ); // اول مارس 2016 ``` -That feature is often used to get the date after the given period of time. For instance, let's get the date for "70 seconds after now": +این ویژگی اغلب برای دریافت تاریخ بعد از مدت زمان داده شده استفاده می‌شود. برای مثال بیایید تاریخ «70 ثانیه پس از الان» را دریافت کنیم: ```js run let date = new Date(); date.setSeconds(date.getSeconds() + 70); -alert( date ); // shows the correct date +alert( date ); // تاریخ درست را نمایش می‌دهد ``` -We can also set zero or even negative values. For example: +همچنین ما می‌توانیم صفر یا مقدارهای منفی را قرار بدهیم. برای مثال: ```js run -let date = new Date(2016, 0, 2); // 2 Jan 2016 +let date = new Date(2016, 0, 2); // دوم ژانویه 2016 -date.setDate(1); // set day 1 of month +date.setDate(1); // روز اول ماه را تنظیم کنید alert( date ); -date.setDate(0); // min day is 1, so the last day of the previous month is assumed -alert( date ); // 31 Dec 2015 +date.setDate(0); // کمترین روز 1 است، پس آخرین روز ماه قبل فرض می‌شود +alert( date ); // سی و یک دسامبر 2015 ``` -## Date to number, date diff +## تبدیل تاریخ به عدد، تقاوت تاریخ -When a `Date` object is converted to number, it becomes the timestamp same as `date.getTime()`: +زمانی که یک شیء `Date` به عدد تبدیل می‌شود، در واقع به مهرزمانی تبدیل می‌شود درست مانند `date.getTime()`: ```js run let date = new Date(); -alert(+date); // the number of milliseconds, same as date.getTime() +alert(+date); // date.getTime() تعداد میلی‌ثانیه‌ها، مانند ``` -The important side effect: dates can be subtracted, the result is their difference in ms. +اثر جانبی مهم: تاریخ‌ها می‌توانند از هم کم شوند، نتیجه برابر با تفاوت آنها در میلی‌ثانیه است. -That can be used for time measurements: +می‌توان از آن برای اندازه‌گیری زمان استفاده کرد: ```js run -let start = new Date(); // start measuring time +let start = new Date(); // شروع به اندازه‌گیری زمان -// do the job +// کارتان را انجام دهید for (let i = 0; i < 100000; i++) { let doSomething = i * i * i; } -let end = new Date(); // end measuring time +let end = new Date(); // اندازه‌گیری زمان را به پایان برسانید -alert( `The loop took ${end - start} ms` ); +alert( `حلقه ${end - start} میلی‌ثانیه طول کشید` ); ``` ## Date.now() From 206704b8af8fa5c3b183b6ae4d4d0f903d3d59ed Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Sun, 15 Aug 2021 22:42:52 +0430 Subject: [PATCH 08/31] Translate a part of article --- 1-js/05-data-types/11-date/article.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 2f869e6ad..0ddbde9a3 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -232,33 +232,33 @@ let end = new Date(); // اندازه‌گیری زمان را به پایان alert( `حلقه ${end - start} میلی‌ثانیه طول کشید` ); ``` -## Date.now() +## متد Date.now() -If we only want to measure time, we don't need the `Date` object. +اگر ما فقط بخواهیم که زمان را اندازه‌گیری کنیم، احتیاجی به شیء `Date` نداریم. -There's a special method `Date.now()` that returns the current timestamp. +یک متد خاص `Date.now()` وجود دارد که مهرزمانی کنونی را برمی‌گرداند. -It is semantically equivalent to `new Date().getTime()`, but it doesn't create an intermediate `Date` object. So it's faster and doesn't put pressure on garbage collection. +از لحاظ معنا برابر با `new Date().getTime()` است اما یک شیء واسطه `Date` نمی‌سازد. پس سریع‌تر است و به زباله‌روبی فشاری وارد نمی‌کند. -It is used mostly for convenience or when performance matters, like in games in JavaScript or other specialized applications. +اغلب اوقات برای راحتی یا زمانی که عملکرد اهمیت دارد استفاده می‌شود، مانند بازی‌های جاوااسکریپت یا برنامه‌های تخصصی دیگر. -So this is probably better: +پس احتمالا این بهتر است: ```js run *!* -let start = Date.now(); // milliseconds count from 1 Jan 1970 +let start = Date.now(); // تعداد میلی‌ثانیه‌ها از اول ژانویه 1970 */!* -// do the job +// کارتان را انجام دهید for (let i = 0; i < 100000; i++) { let doSomething = i * i * i; } *!* -let end = Date.now(); // done +let end = Date.now(); // تمام */!* -alert( `The loop took ${end - start} ms` ); // subtract numbers, not dates +alert( `The loop took ${end - start} ms` ); // اعداد را از هم کم کنید نه تاریخ‌ها را ``` ## Benchmarking From 5808cf570636874aacba3f9d8c1214037ed4afe8 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Mon, 16 Aug 2021 14:40:25 +0430 Subject: [PATCH 09/31] Translate a part of article --- 1-js/05-data-types/11-date/article.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 0ddbde9a3..00266f0b4 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -378,30 +378,30 @@ Modern JavaScript engines perform many optimizations. They may tweak results of The great pack of articles about V8 can be found at . ``` -## Date.parse from a string +## تجزیه رشته به تاریخ با Date.parse -The method [Date.parse(str)](mdn:js/Date/parse) can read a date from a string. +متد [Date.parse(str)](mdn:js/Date/parse) می‌تواند یک تاریخ را از یک رشته بخواند. -The string format should be: `YYYY-MM-DDTHH:mm:ss.sssZ`, where: +شکل رشته باید به این فرمت باشد: `YYYY-MM-DDTHH:mm:ss.sssZ`، با این شرایط: -- `YYYY-MM-DD` -- is the date: year-month-day. -- The character `"T"` is used as the delimiter. -- `HH:mm:ss.sss` -- is the time: hours, minutes, seconds and milliseconds. -- The optional `'Z'` part denotes the time zone in the format `+-hh:mm`. A single letter `Z` would mean UTC+0. +- `YYYY-MM-DD` -- تاریخ است: روز-ماه-سال +- کاراکتر `"T"` به عنوان جداکننده استفاده می‌شود. +- `HH:mm:ss.sss` -- زمان است: میلی‌ثانیه‌ها، ثانیه‌ها، دقیقه‌ها و ساعت‌ها. +- قسمت اختیاری `'Z'` نشان‌دهنده منطقه زمانی به شکل `+-hh:mm` است. حرف تنهای `Z` به معنای UTC+0 است. -Shorter variants are also possible, like `YYYY-MM-DD` or `YYYY-MM` or even `YYYY`. +انواع کوتاه‌تر رشته هم وجود دارند مثل `YYYY-MM-DD` یا `YYYY-MM` یا حتی `YYYY`. -The call to `Date.parse(str)` parses the string in the given format and returns the timestamp (number of milliseconds from 1 Jan 1970 UTC+0). If the format is invalid, returns `NaN`. +فراخوانی `Date.parse(str)` رشته را به فرمت داده شده تجزیه می‌کند و مهرزمانی (تعداد میلی‌ثانیه‌های گذشته از اول ژانویه 1970 با UTC+0) را برمی‌گرداند. اگر فرمت قابل قبول نباشد، `NaN` را برمی‌گرداند. -For instance: +برای مثال: ```js run let ms = Date.parse('2012-01-26T13:51:50.417-07:00'); -alert(ms); // 1327611110417 (timestamp) +alert(ms); // 1327611110417 (مهرزمانی) ``` -We can instantly create a `new Date` object from the timestamp: +ما بلافاصله می‌توانیم از مهرزمانی یک شیء `new Date` بسازیم: ```js run let date = new Date( Date.parse('2012-01-26T13:51:50.417-07:00') ); From 01a108922da537ca2718def2af715521eb55e85b Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Tue, 17 Aug 2021 19:45:13 +0430 Subject: [PATCH 10/31] Translate a part of article --- 1-js/05-data-types/11-date/article.md | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index 00266f0b4..d4b27ea29 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -261,33 +261,33 @@ let end = Date.now(); // تمام alert( `The loop took ${end - start} ms` ); // اعداد را از هم کم کنید نه تاریخ‌ها را ``` -## Benchmarking +## بِنچمارک‌گیری (Benchmarking) -If we want a reliable benchmark of CPU-hungry function, we should be careful. +اگر ما یک بنچمارک قابل اطمینان از تابعی که پردازنده (CPU) را خیلی مشغول می‌کند بخواهیم، باشد مراقب باشیم. -For instance, let's measure two functions that calculate the difference between two dates: which one is faster? +برای مثال، بیایید دو تابع که تفاوت بین دو تاریخ را محاسبه می‌کنند را اندازه‌گیری کنیم: کدام یک از آنها سریع‌تر است؟ -Such performance measurements are often called "benchmarks". +چنین اندازه‌گیری‌های عملکردی را «بِبنچمارک» می‌گویند. ```js -// we have date1 and date2, which function faster returns their difference in ms? +// را داریم، کدام تابع تفاوت آنها به میلی‌ثانیه را سریع‌تر برمی‌گرداند؟ date2 و date1 ما function diffSubtract(date1, date2) { return date2 - date1; } -// or +// یا function diffGetTime(date1, date2) { return date2.getTime() - date1.getTime(); } ``` -These two do exactly the same thing, but one of them uses an explicit `date.getTime()` to get the date in ms, and the other one relies on a date-to-number transform. Their result is always the same. +این دو تابع دقیقا یک کار را انجام می‌دهند اما یکی از آنها برای گرفتن تاریخ به میلی‌ثانیه از متد صریح `date.getTime()` استفاده می‌کند، و دیگری به تبدیل تاریخ به عدد متکی است. نتیجه آنها همیشه یکسان است. -So, which one is faster? +خب، کدام یک سریع‌تر است؟ -The first idea may be to run them many times in a row and measure the time difference. For our case, functions are very simple, so we have to do it at least 100000 times. +ایده اول می‌تواند این باشد که آنها را چند بار متوالی اجرا کند و تفاوت زمان را اندازه بگیرد. در مورد ما، تابع‌ها خیلی ساده هستند، پس ما باید حداقل این کار را 100000 بار انجام دهیم. -Let's measure: +بیایید اندازه بگیریم: ```js run function diffSubtract(date1, date2) { @@ -311,19 +311,19 @@ alert( 'Time of diffSubtract: ' + bench(diffSubtract) + 'ms' ); alert( 'Time of diffGetTime: ' + bench(diffGetTime) + 'ms' ); ``` -Wow! Using `getTime()` is so much faster! That's because there's no type conversion, it is much easier for engines to optimize. +عجب! استفاده از `getTime()` خیلی سریع‌تر است! به این دلیل که هیچ تبدیلی برای نوع انجام نمی‌شود و از لحاظ بهینه‌سازی برای موتورها خیلی سریع‌تر است. -Okay, we have something. But that's not a good benchmark yet. +خب این از هیچی بهتر است. اما هنوز یک بنچمارک خوب نیست. -Imagine that at the time of running `bench(diffSubtract)` CPU was doing something in parallel, and it was taking resources. And by the time of running `bench(diffGetTime)` that work has finished. +فرض کنید که در حین اجرای `bench(diffSubtract)` پردازنده همزمان درحال انجام کاری بود و منابع اشغال می‌شدند. و تا قبل از اجرای `bech(diffGetTime)` آن کار تمام می‌شد. -A pretty real scenario for a modern multi-process OS. +یک سناریو کاملا واقعی برای یک سیستم‌عامل چند وظیفه‌ای مدرن. -As a result, the first benchmark will have less CPU resources than the second. That may lead to wrong results. +در نتیجه، بنچمارک اول منابع پردازنده کمتری نسبت به دومی در اختیار خواهد داشت. اینگونه ممکن است نتایج اشتباه پدید بیایند. -**For more reliable benchmarking, the whole pack of benchmarks should be rerun multiple times.** +**برای بنچمارک قابل اطمینان‌تر، تمام بنچمارک‌ها باشد برای چند بار دوباره اجرا شوند.** -For example, like this: +برای مثال، اینگونه: ```js run function diffSubtract(date1, date2) { @@ -347,7 +347,7 @@ let time1 = 0; let time2 = 0; *!* -// run bench(diffSubtract) and bench(diffGetTime) each 10 times alternating +// را به طور متناوب 10 بار اجرا کن bench(diffSubtract) و bench(diffGetTime) هر کدام از for (let i = 0; i < 10; i++) { time1 += bench(diffSubtract); time2 += bench(diffGetTime); @@ -358,24 +358,24 @@ alert( 'Total time for diffSubtract: ' + time1 ); alert( 'Total time for diffGetTime: ' + time2 ); ``` -Modern JavaScript engines start applying advanced optimizations only to "hot code" that executes many times (no need to optimize rarely executed things). So, in the example above, first executions are not well-optimized. We may want to add a heat-up run: +موتورهای مدرن جاوااسکریپت فقط روی «کدهای خاص» که به تعداد زیادی اجرا می‌شوند، بهینه‌سازی‌های پیشرفته را اعمال می‌کنند (نیازی به بهینه‌سازی چیزهایی که کم اجرا می‌شوند نیست). پس در مثال بالا، اجراهای اولیه کد خوب بهینه‌سازی نمی‌شوند. شاید بخواهیم یک اجرای آماده‌سازی اضافه کنیم: ```js -// added for "heating up" prior to the main loop +// برای «آماده‌سازی» قبل از حلقه اصلی اضافه شدند bench(diffSubtract); bench(diffGetTime); -// now benchmark +// حالا بنچمارک for (let i = 0; i < 10; i++) { time1 += bench(diffSubtract); time2 += bench(diffGetTime); } ``` -```warn header="Be careful doing microbenchmarking" -Modern JavaScript engines perform many optimizations. They may tweak results of "artificial tests" compared to "normal usage", especially when we benchmark something very small, such as how an operator works, or a built-in function. So if you seriously want to understand performance, then please study how the JavaScript engine works. And then you probably won't need microbenchmarks at all. +```warn header="در حین انجام بنچمارک‌های کوچک مراقب باشید" +موتورهای مدرن جاوااسکریپت بهینه‌سازی‌های زیادی انجام می‌دهند. آنها ممکن است نتایج «آزمایش‌های ساختگی» را نسبت به «استفاده معمولی» تغییر دهند، مخصوصا زمانی که ما از چیزی بسیار کوچک مانند اینکه یک عملگر یا یک تابع درون‌ساخت چگونه کار می‌کند را بنچمارک بگیریم. پس اگر به طور جدی می‌خواهید عملکرد را متوجه شوید، لطفا درباره اینکه موتورهای جاوااسکریپت چگونه کار می‌کنند مطالعه کنید. سپس ممکن است کلا به بنچمارک‌های کوچک احتیاجی نداشته باشید. -The great pack of articles about V8 can be found at . +می‌توانید یک دسته از مقاله‌های عالی درباره V8 را در پیدا کنید. ``` ## تجزیه رشته به تاریخ با Date.parse From 87618e33fe1d9b634fcc23917fdf5f76fba964ea Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Wed, 18 Aug 2021 15:20:21 +0430 Subject: [PATCH 11/31] Translate article --- 1-js/05-data-types/11-date/article.md | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index d4b27ea29..fb39ff2de 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -409,24 +409,24 @@ let date = new Date( Date.parse('2012-01-26T13:51:50.417-07:00') ); alert(date); ``` -## Summary +## خلاصه -- Date and time in JavaScript are represented with the [Date](mdn:js/Date) object. We can't create "only date" or "only time": `Date` objects always carry both. -- Months are counted from zero (yes, January is a zero month). -- Days of week in `getDay()` are also counted from zero (that's Sunday). -- `Date` auto-corrects itself when out-of-range components are set. Good for adding/subtracting days/months/hours. -- Dates can be subtracted, giving their difference in milliseconds. That's because a `Date` becomes the timestamp when converted to a number. -- Use `Date.now()` to get the current timestamp fast. +- تاریخ و زمان در جاوااسکریپت با شیء [Date](mdn:js/Date) نمایش داده می‌شوند. ما نمی‌توانیم «فقط تاریخ» یا «فقط زمان» ایجاد کنیم: شیءهای `Date` همیشه هر دو را دارند. +- ماه‌ها از صفر شمرده می‌شوند (بله، ژانویه ماه صفر است). +- روزهای هفته در `getDay()` هم از صفر شمرده می‌شوند (که می‌شود یکشنبه). +- شیء `Date` زمانی که اجزاء خارج از محدوده تنظیم شوند، خودش را به طور خودکار تصحیح می‌کند. این ویژگی برای اضافه‌کردن/کم‌کردن روزها/ماه‌ها/ساعت‌ها خوب است. +- تاریخ‌ها می‌توانند از هم کم شوند که برابر با تفاوت آنها به میلی‌ثانیه است. به این دلیل که یک `Date` زمانی که به عدد تبدیل می‌شود، در واقع به مهرزمانی تبدیل می‌شود. +- برای گرفتن سریع مهرزمانی کنونی از `Date.now()` استفاده کنید. -Note that unlike many other systems, timestamps in JavaScript are in milliseconds, not in seconds. +در نظر داشته باشید که برخلاف بسیاری از سیستم‌های دیگر، مهرزمانی در جاوااسکریپت به میلی‌ثانیه است نه ثانیه. -Sometimes we need more precise time measurements. JavaScript itself does not have a way to measure time in microseconds (1 millionth of a second), but most environments provide it. For instance, browser has [performance.now()](mdn:api/Performance/now) that gives the number of milliseconds from the start of page loading with microsecond precision (3 digits after the point): +بعضی اوقات ما به اندازه‌گیری‌های دقیق‌تر زمان نیاز داریم. خود جاوااسکریپت راهی برای اندازه‌گیری زمان به میلی‌ثانیه ندارد اما اکثر محیط‌های اجرا آن را مهیا می‌کنند. برای مثال، مرورگر [performance.now()](mdn:api/Performance/now) را دارد که تعداد میلی‌ثانیه‌ها را با دقت میکروثانیه (3 رقم بعد از اعشار) از شروع بارگیری صفحه می‌دهد: ```js run -alert(`Loading started ${performance.now()}ms ago`); -// Something like: "Loading started 34731.26000000001ms ago" -// .26 is microseconds (260 microseconds) -// more than 3 digits after the decimal point are precision errors, only the first 3 are correct +alert(`بارگیری ${performance.now()} میلی‌ثانیه پیش شروع شد`); +// «چیزی شبیه به این: «بارگیری 34731.26000000001 میلی‌ثانیه پیش شروع شد +// قسمت 26. میکروثانیه است (260 میکروثانیه) +// بیشتر از 3 رقم بعد از اعشار ارورهای دقت اندازه‌گیری است، فقط 3 رقم اول درست هستند ``` -Node.js has `microtime` module and other ways. Technically, almost any device and environment allows to get more precision, it's just not in `Date`. +محیط Node.js ماژول `microtime` و راه‌های دیگری دارد. به طور فنی، تقریبا هر دستگاه و محیطی به ما امکان گرفتن دقت بیشتر را می‌دهد فقط در `Date` وجود ندارد. From 69b516162fbf9aca198d8c1670a597d0adb0edd6 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:27:45 +0430 Subject: [PATCH 12/31] Translate task of "new date" --- 1-js/05-data-types/11-date/1-new-date/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/05-data-types/11-date/1-new-date/task.md b/1-js/05-data-types/11-date/1-new-date/task.md index 1b40d5ac0..b50413d8f 100644 --- a/1-js/05-data-types/11-date/1-new-date/task.md +++ b/1-js/05-data-types/11-date/1-new-date/task.md @@ -2,8 +2,8 @@ importance: 5 --- -# Create a date +# یک تاریخ بسازید -Create a `Date` object for the date: Feb 20, 2012, 3:12am. The time zone is local. +یک شیء `Date` برای این تاریخ بسازید: 20 فوریه 2012، ساعت 3:12 قبل از ظهر. منطقه زمانی محلی است. -Show it using `alert`. +با استفاده از `alert` آن را نمایش دهید. From 5fdcb7980df3ecacd8a600a686420927ee2e0841 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:31:26 +0430 Subject: [PATCH 13/31] Translate solution of "new date" --- 1-js/05-data-types/11-date/1-new-date/solution.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/05-data-types/11-date/1-new-date/solution.md b/1-js/05-data-types/11-date/1-new-date/solution.md index bed449453..6cfa5a909 100644 --- a/1-js/05-data-types/11-date/1-new-date/solution.md +++ b/1-js/05-data-types/11-date/1-new-date/solution.md @@ -1,15 +1,15 @@ -The `new Date` constructor uses the local time zone. So the only important thing to remember is that months start from zero. +تابع سازنده `new Date` از منطقه زمانی محلی استفاده می‌کند. پس تنها چیز مهم به یاد داشتن این است که ماه‌ها از صفر شروع می‌شوند. -So February has number 1. +پس فوریه عدد 1 را دارد. -Here's an example with numbers as date components: +اینجا یک مثال داریم که دارای اعداد برای اجزاء تاریخ است: ```js run //new Date(year, month, date, hour, minute, second, millisecond) let d1 = new Date(2012, 1, 20, 3, 12); alert( d1 ); ``` -We could also create a date from a string, like this: +ما می‌توانستیم یک تاریخ از یک رشته بسازیم، مانند این: ```js run //new Date(datastring) From 0a19720fe72657ce29f516a3ed575e7f607c6dee Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:34:52 +0430 Subject: [PATCH 14/31] Translate task of "get week day" --- 1-js/05-data-types/11-date/2-get-week-day/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/05-data-types/11-date/2-get-week-day/task.md b/1-js/05-data-types/11-date/2-get-week-day/task.md index 5cf31565d..f225312d8 100644 --- a/1-js/05-data-types/11-date/2-get-week-day/task.md +++ b/1-js/05-data-types/11-date/2-get-week-day/task.md @@ -2,13 +2,13 @@ importance: 5 --- -# Show a weekday +# روز هفته را نشان دهید -Write a function `getWeekDay(date)` to show the weekday in short format: 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'. +یک تابع `getWeekDay(date)` بنویسید که روز هفته را به این شکل نشان می‌دهد: 'MO'، 'TU'، 'WE'، 'TH'، 'FR'، 'SA'، 'SU'. -For instance: +برای مثال: ```js no-beautify let date = new Date(2012, 0, 3); // 3 Jan 2012 -alert( getWeekDay(date) ); // should output "TU" +alert( getWeekDay(date) ); // را نشان دهد "TU" باید ``` From 7ce160b4da30c8b6343c0f1ce72f2a6b446b880e Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:36:46 +0430 Subject: [PATCH 15/31] Translate solution of "get week day" --- 1-js/05-data-types/11-date/2-get-week-day/solution.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/05-data-types/11-date/2-get-week-day/solution.md b/1-js/05-data-types/11-date/2-get-week-day/solution.md index 2acaabf9c..4a3c93b51 100644 --- a/1-js/05-data-types/11-date/2-get-week-day/solution.md +++ b/1-js/05-data-types/11-date/2-get-week-day/solution.md @@ -1,6 +1,6 @@ -The method `date.getDay()` returns the number of the weekday, starting from sunday. +متد `date.getDay()` عدد روز هفته را برمی‌گرداند که از یکشنبه شروع می‌شود. -Let's make an array of weekdays, so that we can get the proper day name by its number: +بیایید یک آرایه از روزهای هفته بسازیم تا بتوانیم اسم روز درست را با عدد آن دریافت کنیم: ```js run function getWeekDay(date) { From 6b24d516f46a85910a44d5c213c69a2f584e5a66 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:40:28 +0430 Subject: [PATCH 16/31] Translate task of "weekday" --- 1-js/05-data-types/11-date/3-weekday/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/05-data-types/11-date/3-weekday/task.md b/1-js/05-data-types/11-date/3-weekday/task.md index ba62790cf..0e8e6e7db 100644 --- a/1-js/05-data-types/11-date/3-weekday/task.md +++ b/1-js/05-data-types/11-date/3-weekday/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# European weekday +# روز هفته اروپایی -European countries have days of week starting with Monday (number 1), then Tuesday (number 2) and till Sunday (number 7). Write a function `getLocalDay(date)` that returns the "European" day of week for `date`. +کشورهای اروپایی روزهای هفته‌شان از دوشنبه (عدد 1) شروع می‌شود، سپس سه‌شنبه (عدد 2) و تا یکشنبه (عدد 7) ادامه دارد. یک تابع `getLocalDay(date)` بنویسید که روز «اروپایی» هفته را به ازای `date` برگرداند. ```js no-beautify let date = new Date(2012, 0, 3); // 3 Jan 2012 -alert( getLocalDay(date) ); // tuesday, should show 2 +alert( getLocalDay(date) ); // سه‌شنبه، باید 2 را برگرداند ``` From 8853862202f090414712e1d4bb0e9f2bcd7cfeb2 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:42:02 +0430 Subject: [PATCH 17/31] Fix a translation mistake --- 1-js/05-data-types/11-date/3-weekday/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/11-date/3-weekday/task.md b/1-js/05-data-types/11-date/3-weekday/task.md index 0e8e6e7db..412dab0fc 100644 --- a/1-js/05-data-types/11-date/3-weekday/task.md +++ b/1-js/05-data-types/11-date/3-weekday/task.md @@ -4,7 +4,7 @@ importance: 5 # روز هفته اروپایی -کشورهای اروپایی روزهای هفته‌شان از دوشنبه (عدد 1) شروع می‌شود، سپس سه‌شنبه (عدد 2) و تا یکشنبه (عدد 7) ادامه دارد. یک تابع `getLocalDay(date)` بنویسید که روز «اروپایی» هفته را به ازای `date` برگرداند. +کشورهای اروپایی روزهای هفته‌شان از دوشنبه (عدد 1) شروع می‌شود، سپس سه‌شنبه (عدد 2) و تا یکشنبه (عدد 7) ادامه دارد. یک تابع `getLocalDay(date)` بنویسید که روز هفته «اروپایی» را به ازای `date` برگرداند. ```js no-beautify let date = new Date(2012, 0, 3); // 3 Jan 2012 From db88420d6b777c07dfd715a3741d4ab0e7c47926 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Thu, 19 Aug 2021 15:43:56 +0430 Subject: [PATCH 18/31] Translate solution.js of "weekday" --- 1-js/05-data-types/11-date/3-weekday/_js.view/solution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/11-date/3-weekday/_js.view/solution.js b/1-js/05-data-types/11-date/3-weekday/_js.view/solution.js index fb9e3d2a4..e24a71308 100644 --- a/1-js/05-data-types/11-date/3-weekday/_js.view/solution.js +++ b/1-js/05-data-types/11-date/3-weekday/_js.view/solution.js @@ -2,7 +2,7 @@ function getLocalDay(date) { let day = date.getDay(); - if (day == 0) { // weekday 0 (sunday) is 7 in european + if (day == 0) { // روز هفته 0 (یکشنبه) به اروپایی برابر با 7 است day = 7; } From 251de896cf7125ec7c115858b4bf620aa74c9eca Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:15:59 +0430 Subject: [PATCH 19/31] Translate task of "get date ago" --- 1-js/05-data-types/11-date/4-get-date-ago/task.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/05-data-types/11-date/4-get-date-ago/task.md b/1-js/05-data-types/11-date/4-get-date-ago/task.md index 058d39c7e..2d3972562 100644 --- a/1-js/05-data-types/11-date/4-get-date-ago/task.md +++ b/1-js/05-data-types/11-date/4-get-date-ago/task.md @@ -2,13 +2,13 @@ importance: 4 --- -# Which day of month was many days ago? +# چند روز قبل کدام روز ماه بود؟ -Create a function `getDateAgo(date, days)` to return the day of month `days` ago from the `date`. +یک تابع `getDateAgo(date, days)` بسازید که روز ماه را به اندازه `days` روز قبل از `date` برگرداند. -For instance, if today is 20th, then `getDateAgo(new Date(), 1)` should be 19th and `getDateAgo(new Date(), 2)` should be 18th. +برای مثال، اگر امروز 20ام باشد، سپس `getDateAgo(new Date(), 1)` باید 19ام را برگرداند و `getDateAgo(new Date(), 2)` باید 18ام باشد. -Should work reliably for `days=365` or more: +باید به ازای `days=365` یا بیشتر به درستی کار کند: ```js let date = new Date(2015, 0, 2); @@ -18,4 +18,4 @@ alert( getDateAgo(date, 2) ); // 31, (31 Dec 2014) alert( getDateAgo(date, 365) ); // 2, (2 Jan 2014) ``` -P.S. The function should not modify the given `date`. +پی‌نوشت: تابع نباید `date` داده شده را تغییر دهد. From 9fdba6a779738dfc851bb620fcdb6a1d3d5aea12 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:20:16 +0430 Subject: [PATCH 20/31] Translate solution of "get date ago" --- 1-js/05-data-types/11-date/4-get-date-ago/solution.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/05-data-types/11-date/4-get-date-ago/solution.md b/1-js/05-data-types/11-date/4-get-date-ago/solution.md index 7abc7ab9c..79dd5c96c 100644 --- a/1-js/05-data-types/11-date/4-get-date-ago/solution.md +++ b/1-js/05-data-types/11-date/4-get-date-ago/solution.md @@ -1,4 +1,4 @@ -The idea is simple: to substract given number of days from `date`: +ایده ساده‌ای است: تعداد روز داده شده را از `date` کم کنید: ```js function getDateAgo(date, days) { @@ -7,9 +7,9 @@ function getDateAgo(date, days) { } ``` -...But the function should not change `date`. That's an important thing, because the outer code which gives us the date does not expect it to change. +...اما تابع نباید `date` را تغییر دهد. این مهم است چون کد بیرونی که به ما تاریخ را می‌دهد توقع ندارد که تاریخ تغییر کند. -To implement it let's clone the date, like this: +برای پیاده‌سازی آن بیایید از تاریخ یک مشابه بسازیم، مانند این: ```js run function getDateAgo(date, days) { From 5cb395aaecc557ce70feff425d369ca89f1bec2f Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:23:50 +0430 Subject: [PATCH 21/31] Translate task of "last day of month" --- .../11-date/5-last-day-of-month/task.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/1-js/05-data-types/11-date/5-last-day-of-month/task.md b/1-js/05-data-types/11-date/5-last-day-of-month/task.md index 10dfb7a7a..f3c68d9d3 100644 --- a/1-js/05-data-types/11-date/5-last-day-of-month/task.md +++ b/1-js/05-data-types/11-date/5-last-day-of-month/task.md @@ -2,13 +2,13 @@ importance: 5 --- -# Last day of month? +# آخرین روز ماه؟ -Write a function `getLastDayOfMonth(year, month)` that returns the last day of month. Sometimes it is 30th, 31st or even 28/29th for Feb. +تابع `getLastDayOfMonth(year, month)` را بنویسید که آخرین روز ماه را برمی‌گرداند. بعضی اوقات آخرین روز 30ام، 31ام یا حتی برای ماه فوریه 28/29ام است. -Parameters: +پارامترها: -- `year` -- four-digits year, for instance 2012. -- `month` -- month, from 0 to 11. +- `year` -- سال 4 رقمی، برای مثال 2012. +- `month` -- ماه، از 0 تا 11. -For instance, `getLastDayOfMonth(2012, 1) = 29` (leap year, Feb). +برای مثال، `getLastDayOfMonth(2012, 1) = 29` (سال کبیسه، فوریه). From 6eaa1cae7962f6bca05b98e92c8ec60959b6d6c2 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:26:53 +0430 Subject: [PATCH 22/31] Translate solution of "last day of month" --- 1-js/05-data-types/11-date/5-last-day-of-month/solution.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/05-data-types/11-date/5-last-day-of-month/solution.md b/1-js/05-data-types/11-date/5-last-day-of-month/solution.md index 65f61c5ba..c024199ac 100644 --- a/1-js/05-data-types/11-date/5-last-day-of-month/solution.md +++ b/1-js/05-data-types/11-date/5-last-day-of-month/solution.md @@ -1,4 +1,4 @@ -Let's create a date using the next month, but pass zero as the day: +بیایید یک تاریخ با استفاده از ماه بعد بسازیم اما برای روز 0 را قرار دهیم: ```js run function getLastDayOfMonth(year, month) { let date = new Date(year, month + 1, 0); @@ -10,4 +10,4 @@ alert( getLastDayOfMonth(2012, 1) ); // 29 alert( getLastDayOfMonth(2013, 1) ); // 28 ``` -Normally, dates start from 1, but technically we can pass any number, the date will autoadjust itself. So when we pass 0, then it means "one day before 1st day of the month", in other words: "the last day of the previous month". +به صورت طبیعی، روزها از 1 شروع می‌شوند اما از لحاظ فنی ما می‌توانیم هر عددی را قرار دهیم، شیء date به طور خودکار خودش را تنظیم می‌کند. پس زمانی که ما 0 قرار می‌دهیم، به این معنی است که «یک روز قبل از اولین روز ماه» یا به عبارتی دیگر: «آخرین روز ماه قبل». From bfa29a048610d249ab1305f6960380d0e717f075 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:29:54 +0430 Subject: [PATCH 23/31] Translate task of "get seconds today" --- 1-js/05-data-types/11-date/6-get-seconds-today/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/05-data-types/11-date/6-get-seconds-today/task.md b/1-js/05-data-types/11-date/6-get-seconds-today/task.md index 456790928..b834a716c 100644 --- a/1-js/05-data-types/11-date/6-get-seconds-today/task.md +++ b/1-js/05-data-types/11-date/6-get-seconds-today/task.md @@ -2,14 +2,14 @@ importance: 5 --- -# How many seconds have passed today? +# چند ثانیه از امروز گذشته است؟ -Write a function `getSecondsToday()` that returns the number of seconds from the beginning of today. +تابع `getSecondsToday()` را بنویسید که تعداد ثانیه‌هایی که از شروع روز گذشته است را برگرداند. -For instance, if now were `10:00 am`, and there was no daylight savings shift, then: +برای مثال، اگر الان `10:00 am` (قبل از ظهر) باشد و ساعت تابستانی هم وجود نداشته باشد، سپس داریم: ```js getSecondsToday() == 36000 // (3600 * 10) ``` -The function should work in any day. That is, it should not have a hard-coded value of "today". +تابع باید به ازای هر روزی کار کند. یعنی اینکه نباید برای «امروز» کد اختصاصی داشته باشد. From 1d1095c8e4e925240f5f4c965aa0cd40e4a96257 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 15:34:06 +0430 Subject: [PATCH 24/31] Translate solution of "get seconds today" --- .../11-date/6-get-seconds-today/solution.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/05-data-types/11-date/6-get-seconds-today/solution.md b/1-js/05-data-types/11-date/6-get-seconds-today/solution.md index 8f8e52b68..1cb91f8da 100644 --- a/1-js/05-data-types/11-date/6-get-seconds-today/solution.md +++ b/1-js/05-data-types/11-date/6-get-seconds-today/solution.md @@ -1,22 +1,22 @@ -To get the number of seconds, we can generate a date using the current day and time 00:00:00, then substract it from "now". +برای دریافت تعداد ثانیه‌ها، ما می‌توانیم با استفاده از روز کنونی و ساعت 00:00:00 یک تاریخ بسازیم، سپس آن را از «الان» کم کنیم. -The difference is the number of milliseconds from the beginning of the day, that we should divide by 1000 to get seconds: +تفاضل برابر با تعداد میلی‌ثانیه‌ها از شروع امروز است که ما باید برای دریافت ثانیه‌ها آن را بر 1000 تقسیم کنیم: ```js run function getSecondsToday() { let now = new Date(); - - // create an object using the current day/month/year + + // با استفاده از سال/ماه/روز کنونی یک شیء بسازید let today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); - let diff = now - today; // ms difference - return Math.round(diff / 1000); // make seconds + let diff = now - today; // تفاضل به میلی‌ثانیه + return Math.round(diff / 1000); // ایجاد ثانیه } alert( getSecondsToday() ); ``` -An alternative solution would be to get hours/minutes/seconds and convert them to seconds: +یک راه حل جایگزین می‌تواند این باشد که ساعت/دقیقه/ثانیه را دریافت کنیم و آنها را به ثانیه تبدیل کنیم: ```js run function getSecondsToday() { From 9ac03694d6a833c9096493d8ae852ef6e0634ffa Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:13:43 +0430 Subject: [PATCH 25/31] Translate task of "get seconds to tomorrow" --- .../11-date/7-get-seconds-to-tomorrow/task.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/task.md b/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/task.md index e05903026..40fd7c8f3 100644 --- a/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/task.md +++ b/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/task.md @@ -2,14 +2,14 @@ importance: 5 --- -# How many seconds till tomorrow? +# چند ثانیه تا فردا مانده است؟ -Create a function `getSecondsToTomorrow()` that returns the number of seconds till tomorrow. +تابع `getSecondsToTomorrow()` بسازید که تعداد ثانیه‌ها را تا فردا برمی‌گرداند. -For instance, if now is `23:00`, then: +برای مثال، اگر الان `23:00` باشد داریم: ```js getSecondsToTomorrow() == 3600 ``` -P.S. The function should work at any day, the "today" is not hardcoded. +پی‌نوشت: تابع باشد به ازای هر روزی کار کند، «امروز» کد اختصاصی ندارد. From 44fc7a191eaf3cc9b5f9d84c0fe39cd08740d975 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:17:54 +0430 Subject: [PATCH 26/31] Translate solution of "get seconds to tomorrow" --- .../11-date/7-get-seconds-to-tomorrow/solution.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md b/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md index c337d1199..785f08962 100644 --- a/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md +++ b/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md @@ -1,20 +1,20 @@ -To get the number of milliseconds till tomorrow, we can from "tomorrow 00:00:00" substract the current date. +برای گرفتن تعداد میلی‌ثانیه‌ها تا فردا، می‌توانیم از «فردا 00:00:00» تاریخ کنونی را کم کنیم. -First, we generate that "tomorrow", and then do it: +اول، ما «فردا» را ایجاد می‌کنیم و سپس این کار را انجام می‌دهیم: ```js run function getSecondsToTomorrow() { let now = new Date(); - // tomorrow date + // تاریخ فردا let tomorrow = new Date(now.getFullYear(), now.getMonth(), *!*now.getDate()+1*/!*); - let diff = tomorrow - now; // difference in ms - return Math.round(diff / 1000); // convert to seconds + let diff = tomorrow - now; // تفاضل در میلی‌ثانیه + return Math.round(diff / 1000); // تبدیل به ثانیه } ``` -Alternative solution: +راه حل جایگزین: ```js run function getSecondsToTomorrow() { @@ -29,4 +29,4 @@ function getSecondsToTomorrow() { } ``` -Please note that many countries have Daylight Savings Time (DST), so there may be days with 23 or 25 hours. We may want to treat such days separately. +لطفا در نظر داشته باشید که بسیاری از کشورها ساعت تابستانی دارند (DST)، پس ممکن است بعضی از روزها 23 یا 25 ساعت داشته باشند. شاید بهتر است با چنین روزهایی متفاوت رفتار کنیم. From db6f956030ea31ffee8cbae682b170afd18d59ed Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:18:23 +0430 Subject: [PATCH 27/31] Fix a translation mistake --- .../05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md b/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md index 785f08962..86dddaa04 100644 --- a/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md +++ b/1-js/05-data-types/11-date/7-get-seconds-to-tomorrow/solution.md @@ -9,7 +9,7 @@ function getSecondsToTomorrow() { // تاریخ فردا let tomorrow = new Date(now.getFullYear(), now.getMonth(), *!*now.getDate()+1*/!*); - let diff = tomorrow - now; // تفاضل در میلی‌ثانیه + let diff = tomorrow - now; // تفاضل به میلی‌ثانیه return Math.round(diff / 1000); // تبدیل به ثانیه } ``` From 306ddb79d33c86131989e306a14adc8c49ca523e Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:28:38 +0430 Subject: [PATCH 28/31] Translate task of "format date relative" --- .../11-date/8-format-date-relative/task.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/1-js/05-data-types/11-date/8-format-date-relative/task.md b/1-js/05-data-types/11-date/8-format-date-relative/task.md index 9651b305f..3cc989ef9 100644 --- a/1-js/05-data-types/11-date/8-format-date-relative/task.md +++ b/1-js/05-data-types/11-date/8-format-date-relative/task.md @@ -2,16 +2,16 @@ importance: 4 --- -# Format the relative date +# تاریخ مربوط را تغییر شکل دهید -Write a function `formatDate(date)` that should format `date` as follows: +تابع `formatDate(date)` بنویسید که باید `date` را به صورت زیر تغییر شکل دهد: -- If since `date` passed less than 1 second, then `"right now"`. -- Otherwise, if since `date` passed less than 1 minute, then `"n sec. ago"`. -- Otherwise, if less than an hour, then `"m min. ago"`. -- Otherwise, the full date in the format `"DD.MM.YY HH:mm"`. That is: `"day.month.year hours:minutes"`, all in 2-digit format, e.g. `31.12.16 10:00`. +- اگر از `date` کمتر از 1 ثانیه گذشته باشد، سپس شکل جدید `"right now"`(همین حالا) است. +- در غیر این صورت اگر از `date` کمتر از 1 دقیقه گذشته باشد، سپس شکل چدید `"n sec. ago"`(n ثانیه قبل) است. +- در غیر این صورت اگر کمتر از یک ساعت باشد، سپس شکل جدید `"m min. ago"`(m دقیقه پیش) است. +- در غیر این صورت، تاریخ کامل با به شکل `"DD.MM.YY HH:mm"` باشد. یعنی: `"day.month.year hours:minutes"`، همه به شکل دو رقمی مانند `10:00 31.12.16`. -For instance: +برای مثال: ```js alert( formatDate(new Date(new Date - 1)) ); // "right now" @@ -20,6 +20,6 @@ alert( formatDate(new Date(new Date - 30 * 1000)) ); // "30 sec. ago" alert( formatDate(new Date(new Date - 5 * 60 * 1000)) ); // "5 min. ago" -// yesterday's date like 31.12.16 20:00 +// تاریخ دیروز مانند 20:00 31.12.16 alert( formatDate(new Date(new Date - 86400 * 1000)) ); ``` From 725e637a62b8a22ea8c0206907abd0d60bcd0a07 Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 16:34:47 +0430 Subject: [PATCH 29/31] Translate solution of "format date relative" --- .../8-format-date-relative/solution.md | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/1-js/05-data-types/11-date/8-format-date-relative/solution.md b/1-js/05-data-types/11-date/8-format-date-relative/solution.md index 372485685..adeedd937 100644 --- a/1-js/05-data-types/11-date/8-format-date-relative/solution.md +++ b/1-js/05-data-types/11-date/8-format-date-relative/solution.md @@ -1,26 +1,26 @@ -To get the time from `date` till now -- let's substract the dates. +برای گرفتن زمان از `date` تا الان، بیایید تفاضل تاریخ‌ها را بیابیم. ```js run demo function formatDate(date) { - let diff = new Date() - date; // the difference in milliseconds + let diff = new Date() - date; // تفاضل به میلی‌ثانیه if (diff < 1000) { // less than 1 second return 'right now'; } - let sec = Math.floor(diff / 1000); // convert diff to seconds + let sec = Math.floor(diff / 1000); // به ثانیه diff تبدیل if (sec < 60) { return sec + ' sec. ago'; } - let min = Math.floor(diff / 60000); // convert diff to minutes + let min = Math.floor(diff / 60000); // به دقیقه diff تبدیل if (min < 60) { return min + ' min. ago'; } - // format the date - // add leading zeroes to single-digit day/month/hours/minutes + // تغییر دادن شکل تاریخ + // اضافه کردن صفر به دقیقه/ساعت/ماه/روز تک رقمی let d = date; d = [ '0' + d.getDate(), @@ -28,9 +28,9 @@ function formatDate(date) { '' + d.getFullYear(), '0' + d.getHours(), '0' + d.getMinutes() - ].map(component => component.slice(-2)); // take last 2 digits of every component + ].map(component => component.slice(-2)); // دریافت 2 رقم آخر هر جزء - // join the components into date + // متصل کردن اجزاء برای ایجاد تاریخ return d.slice(0, 3).join('.') + ' ' + d.slice(3).join(':'); } @@ -40,11 +40,11 @@ alert( formatDate(new Date(new Date - 30 * 1000)) ); // "30 sec. ago" alert( formatDate(new Date(new Date - 5 * 60 * 1000)) ); // "5 min. ago" -// yesterday's date like 31.12.2016 20:00 +// تاریخ دیروز مانند 20:00 31.12.2016 alert( formatDate(new Date(new Date - 86400 * 1000)) ); ``` -Alternative solution: +راه حل جایگزین: ```js run function formatDate(date) { @@ -58,7 +58,7 @@ function formatDate(date) { let diffMin = diffSec / 60; let diffHour = diffMin / 60; - // formatting + // تغییر دادن شکل year = year.toString().slice(-2); month = month < 10 ? '0' + month : month; dayOfMonth = dayOfMonth < 10 ? '0' + dayOfMonth : dayOfMonth; From 648200767fe29655ea789d4a97304169c034407e Mon Sep 17 00:00:00 2001 From: Mahdyar Hasanpour Date: Fri, 20 Aug 2021 21:16:51 +0430 Subject: [PATCH 30/31] fix: fix a typo --- 1-js/05-data-types/11-date/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index fb39ff2de..a78fdf658 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -267,7 +267,7 @@ alert( `The loop took ${end - start} ms` ); // اعداد را از هم کم ک برای مثال، بیایید دو تابع که تفاوت بین دو تاریخ را محاسبه می‌کنند را اندازه‌گیری کنیم: کدام یک از آنها سریع‌تر است؟ -چنین اندازه‌گیری‌های عملکردی را «بِبنچمارک» می‌گویند. +چنین اندازه‌گیری‌های عملکردی را «بِنچمارک» می‌گویند. ```js // را داریم، کدام تابع تفاوت آنها به میلی‌ثانیه را سریع‌تر برمی‌گرداند؟ date2 و date1 ما From 8d31cd366b4a22085a49945abd4fb5f10127f80b Mon Sep 17 00:00:00 2001 From: MaHdi <72219881+mahdiHashemi14@users.noreply.github.com> Date: Fri, 20 Aug 2021 22:08:17 +0430 Subject: [PATCH 31/31] =?UTF-8?q?Change=20"=D9=85=D9=87=D8=B1=D8=B2=D9=85?= =?UTF-8?q?=D8=A7=D9=86=DB=8C"=20to=20"=D8=A8=D8=B1=DA=86=D8=B3=D8=A8=20?= =?UTF-8?q?=D8=B2=D9=85=D8=A7=D9=86"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/05-data-types/11-date/article.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/1-js/05-data-types/11-date/article.md b/1-js/05-data-types/11-date/article.md index a78fdf658..f103f1c88 100644 --- a/1-js/05-data-types/11-date/article.md +++ b/1-js/05-data-types/11-date/article.md @@ -29,11 +29,11 @@ alert( Jan02_1970 ); ``` - عدد صحیحی که تعداد میلی‌ثانیه‌های گذشته از شروع 1970 را نمایش می‌دهد را *مُهرزمانی (timestamp)* می‌گویند. + عدد صحیحی که تعداد میلی‌ثانیه‌های گذشته از شروع 1970 را نمایش می‌دهد را *برچسب زمان (timestamp)* می‌گویند. - مهرزمانی یک نمایش آسان از تاریخ است. ما همیشه می‌توانیم با استفاده از `new Date(timestamp)` یک تاریخ را از یک مهرزمانی بسازیم و شیء `Date` موجود را با استفاده از متد `date.getTime()` به مهرزمانی تبدیل کنیم (ادامه متن را ببینید). + برچسب زمان یک نمایش آسان از تاریخ است. ما همیشه می‌توانیم با استفاده از `new Date(timestamp)` یک تاریخ را از یک برچسب زمان بسازیم و شیء `Date` موجود را با استفاده از متد `date.getTime()` به برچسب زمان تبدیل کنیم (ادامه متن را ببینید). - :تاریخ‌های قبل از 01.01.1970 مهرزمانی منفی دارند، برای مثال + :تاریخ‌های قبل از 01.01.1970 برچسب زمان منفی دارند، برای مثال ```js run // سی و یک دسامبر 1969 let Dec31_1969 = new Date(-24 * 3600 * 1000); @@ -121,7 +121,7 @@ alert( date.getUTCHours() ); علاوه بر متدهای داده شده، دو متد خاص هم وجود دارند که نوع UTC برای آنها وجود ندارد: [getTime()](mdn:js/Date/getTime) -: مهرزمانی را برای تاریخ برمی‌گرداند -- عددی برابر با میلی‌ثانیه‌هایی که از اول ژانویه 1970 میلادی با UTC+0 گذشته است. +: برچسب زمان را برای تاریخ برمی‌گرداند -- عددی برابر با میلی‌ثانیه‌هایی که از اول ژانویه 1970 میلادی با UTC+0 گذشته است. [getTimezoneOffset()](mdn:js/Date/getTimezoneOffset) : تقاوت بین UTC و منطقه زمانی محلی را به دقیقه برمی‌گرداند. @@ -208,7 +208,7 @@ alert( date ); // سی و یک دسامبر 2015 ## تبدیل تاریخ به عدد، تقاوت تاریخ -زمانی که یک شیء `Date` به عدد تبدیل می‌شود، در واقع به مهرزمانی تبدیل می‌شود درست مانند `date.getTime()`: +زمانی که یک شیء `Date` به عدد تبدیل می‌شود، در واقع به برچسب زمان تبدیل می‌شود درست مانند `date.getTime()`: ```js run let date = new Date(); @@ -236,7 +236,7 @@ alert( `حلقه ${end - start} میلی‌ثانیه طول کشید` ); اگر ما فقط بخواهیم که زمان را اندازه‌گیری کنیم، احتیاجی به شیء `Date` نداریم. -یک متد خاص `Date.now()` وجود دارد که مهرزمانی کنونی را برمی‌گرداند. +یک متد خاص `Date.now()` وجود دارد که برچسب زمان کنونی را برمی‌گرداند. از لحاظ معنا برابر با `new Date().getTime()` است اما یک شیء واسطه `Date` نمی‌سازد. پس سریع‌تر است و به زباله‌روبی فشاری وارد نمی‌کند. @@ -391,17 +391,17 @@ for (let i = 0; i < 10; i++) { انواع کوتاه‌تر رشته هم وجود دارند مثل `YYYY-MM-DD` یا `YYYY-MM` یا حتی `YYYY`. -فراخوانی `Date.parse(str)` رشته را به فرمت داده شده تجزیه می‌کند و مهرزمانی (تعداد میلی‌ثانیه‌های گذشته از اول ژانویه 1970 با UTC+0) را برمی‌گرداند. اگر فرمت قابل قبول نباشد، `NaN` را برمی‌گرداند. +فراخوانی `Date.parse(str)` رشته را به فرمت داده شده تجزیه می‌کند و برچسب زمان (تعداد میلی‌ثانیه‌های گذشته از اول ژانویه 1970 با UTC+0) را برمی‌گرداند. اگر فرمت قابل قبول نباشد، `NaN` را برمی‌گرداند. برای مثال: ```js run let ms = Date.parse('2012-01-26T13:51:50.417-07:00'); -alert(ms); // 1327611110417 (مهرزمانی) +alert(ms); // 1327611110417 (برچسب زمان) ``` -ما بلافاصله می‌توانیم از مهرزمانی یک شیء `new Date` بسازیم: +ما بلافاصله می‌توانیم از برچسب زمان یک شیء `new Date` بسازیم: ```js run let date = new Date( Date.parse('2012-01-26T13:51:50.417-07:00') ); @@ -415,10 +415,10 @@ alert(date); - ماه‌ها از صفر شمرده می‌شوند (بله، ژانویه ماه صفر است). - روزهای هفته در `getDay()` هم از صفر شمرده می‌شوند (که می‌شود یکشنبه). - شیء `Date` زمانی که اجزاء خارج از محدوده تنظیم شوند، خودش را به طور خودکار تصحیح می‌کند. این ویژگی برای اضافه‌کردن/کم‌کردن روزها/ماه‌ها/ساعت‌ها خوب است. -- تاریخ‌ها می‌توانند از هم کم شوند که برابر با تفاوت آنها به میلی‌ثانیه است. به این دلیل که یک `Date` زمانی که به عدد تبدیل می‌شود، در واقع به مهرزمانی تبدیل می‌شود. -- برای گرفتن سریع مهرزمانی کنونی از `Date.now()` استفاده کنید. +- تاریخ‌ها می‌توانند از هم کم شوند که برابر با تفاوت آنها به میلی‌ثانیه است. به این دلیل که یک `Date` زمانی که به عدد تبدیل می‌شود، در واقع به برچسب زمان تبدیل می‌شود. +- برای گرفتن سریع برچسب زمان کنونی از `Date.now()` استفاده کنید. -در نظر داشته باشید که برخلاف بسیاری از سیستم‌های دیگر، مهرزمانی در جاوااسکریپت به میلی‌ثانیه است نه ثانیه. +در نظر داشته باشید که برخلاف بسیاری از سیستم‌های دیگر، برچسب زمان در جاوااسکریپت به میلی‌ثانیه است نه ثانیه. بعضی اوقات ما به اندازه‌گیری‌های دقیق‌تر زمان نیاز داریم. خود جاوااسکریپت راهی برای اندازه‌گیری زمان به میلی‌ثانیه ندارد اما اکثر محیط‌های اجرا آن را مهیا می‌کنند. برای مثال، مرورگر [performance.now()](mdn:api/Performance/now) را دارد که تعداد میلی‌ثانیه‌ها را با دقت میکروثانیه (3 رقم بعد از اعشار) از شروع بارگیری صفحه می‌دهد: