-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# now | ||
|
||
::: info | ||
この関数は互換性のために `es-toolkit/compat` からのみインポートできます。代替可能なネイティブ JavaScript API があるか、まだ十分に最適化されていないためです。 | ||
|
||
`es-toolkit/compat` からこの関数をインポートすると、[lodash と完全に同じように動作](../../../compatibility.md)します。 | ||
::: | ||
|
||
1970年1月1日00:00:00 UTCから経過したミリ秒数を返します。 | ||
|
||
## インターフェース | ||
|
||
```typescript | ||
function now(): number; | ||
``` | ||
|
||
### 戻り値 | ||
|
||
(`number`): 1970年1月1日00:00:00 UTC以降に経過したミリ秒。 | ||
|
||
## 例 | ||
|
||
```typescript | ||
const currentTime = now(); | ||
console.log(currentTime); // Outputs the current time in milliseconds | ||
|
||
const startTime = now(); | ||
// Some time-consuming operation | ||
const endTime = now(); | ||
console.log(`Operation took ${endTime - startTime} milliseconds`); | ||
``` |
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# now | ||
|
||
::: info | ||
이 함수는 호환성을 위한 `es-toolkit/compat` 에서만 가져올 수 있어요. 대체할 수 있는 네이티브 JavaScript API가 있거나, 아직 충분히 최적화되지 않았기 때문이에요. | ||
|
||
`es-toolkit/compat`에서 이 함수를 가져오면, [lodash와 완전히 똑같이 동작](../../../compatibility.md)해요. | ||
::: | ||
|
||
1970년 1월 1일 00:00:00 UTC 이후 경과된 밀리초를 반환해요. | ||
|
||
## 인터페이스 | ||
|
||
```typescript | ||
function now(): number; | ||
``` | ||
|
||
### 반환 값 | ||
|
||
(`number`): 1970년 1월 1일 00:00:00 UTC 이후 경과된 밀리초. | ||
|
||
## 예시 | ||
|
||
```typescript | ||
const currentTime = now(); | ||
console.log(currentTime); // Outputs the current time in milliseconds | ||
|
||
const startTime = now(); | ||
// Some time-consuming operation | ||
const endTime = now(); | ||
console.log(`Operation took ${endTime - startTime} milliseconds`); | ||
``` |
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# now | ||
|
||
::: info | ||
This function is only available in `es-toolkit/compat` for compatibility reasons. It either has alternative native JavaScript APIs or isn’t fully optimized yet. | ||
|
||
When imported from `es-toolkit/compat`, it behaves exactly like lodash and provides the same functionalities, as detailed [here](../../../compatibility.md). | ||
::: | ||
|
||
Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC. | ||
|
||
## Signature | ||
|
||
```typescript | ||
function now(): number; | ||
``` | ||
|
||
### Returns | ||
|
||
(`number`): The current time in milliseconds. | ||
|
||
## Examples | ||
|
||
```typescript | ||
const currentTime = now(); | ||
console.log(currentTime); // Outputs the current time in milliseconds | ||
|
||
const startTime = now(); | ||
// Some time-consuming operation | ||
const endTime = now(); | ||
console.log(`Operation took ${endTime - startTime} milliseconds`); | ||
``` |
This file contains 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# now | ||
|
||
::: info | ||
出于兼容性原因,此函数仅在 `es-toolkit/compat` 中提供。它可能具有替代的原生 JavaScript API,或者尚未完全优化。 | ||
|
||
从 `es-toolkit/compat` 导入时,它的行为与 lodash 完全一致,并提供相同的功能,详情请见 [这里](../../../compatibility.md)。 | ||
::: | ||
|
||
返回自1970年1月1日00:00:00 UTC以来经过的毫秒数。 | ||
|
||
## 签名 | ||
|
||
```typescript | ||
function now(): number; | ||
``` | ||
|
||
### 返回值 | ||
|
||
(`number`): 自1970年1月1日00:00:00 UTC以来经过的毫秒数。 | ||
|
||
## 示例 | ||
|
||
```typescript | ||
const currentTime = now(); | ||
console.log(currentTime); // Outputs the current time in milliseconds | ||
|
||
const startTime = now(); | ||
// Some time-consuming operation | ||
const endTime = now(); | ||
console.log(`Operation took ${endTime - startTime} milliseconds`); | ||
``` |
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { now } from './now'; | ||
import { delay } from '../../promise/delay'; | ||
|
||
describe('now', () => { | ||
it('should return the number of milliseconds that have elapsed since the Unix epoch', async () => { | ||
const stamp = +new Date(); | ||
const actual = now(); | ||
|
||
expect(actual).toBeGreaterThanOrEqual(stamp); | ||
|
||
await delay(32); | ||
|
||
expect(now() > actual); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC. | ||
* | ||
* @returns {number} The current time in milliseconds. | ||
* | ||
* @example | ||
* const currentTime = now(); | ||
* console.log(currentTime); // Outputs the current time in milliseconds | ||
* | ||
* @example | ||
* const startTime = now(); | ||
* // Some time-consuming operation | ||
* const endTime = now(); | ||
* console.log(`Operation took ${endTime - startTime} milliseconds`); | ||
*/ | ||
export function now(): number { | ||
return Date.now(); | ||
} |