Skip to content

Commit

Permalink
Merge branch 'main' into renovate/all-minor-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
hmbanan666 authored Jun 25, 2024
2 parents 0eaa037 + 539061a commit 05b11f9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"dbaeumer.vscode-eslint",
"svelte.svelte-vscode",
"ms-azuretools.vscode-docker",
"vitest.explorer"
"vitest.explorer",
"Codeium.codeium"
]
}
},
Expand Down
42 changes: 18 additions & 24 deletions src/lib/utils/__tests__/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,66 @@ import { getDateMinusMinutes, getDatePlusMinutes, getDatePlusSeconds } from '$li

describe('getDatePlusMinutes()', () => {
it('returns the current date and time plus the specified minutes', () => {
const now = new Date()
const minutesToAdd = 5
const result = getDatePlusMinutes(minutesToAdd)
const expected = new Date(now.getTime() + minutesToAdd * 60 * 1000)
expect(result.getTime()).toBeCloseTo(expected.getTime(), 2)
const expected = new Date(Date.now() + minutesToAdd * 60 * 1000)
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})

it('handles the edge case of zero minutes', () => {
const now = new Date()
const result = getDatePlusMinutes(0)
expect(result.getTime()).toBeCloseTo(now.getTime(), 2)
const expected = new Date()
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})

it('handles the edge case of negative minutes', () => {
const now = new Date()
const minutesToAdd = -5
const result = getDatePlusMinutes(minutesToAdd)
const expected = new Date(now.getTime() + minutesToAdd * 60 * 1000)
expect(result.getTime()).toBeCloseTo(expected.getTime(), 2)
const expected = new Date(Date.now() + minutesToAdd * 60 * 1000)
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})
})

describe('getDateMinusMinutes()', () => {
it('returns the current date and time minus the specified minutes', () => {
const now = new Date()
const minutesToSubtract = 5
const result = getDateMinusMinutes(minutesToSubtract)
const expected = new Date(now.getTime() - minutesToSubtract * 60 * 1000)
expect(result.getTime()).toBeCloseTo(expected.getTime(), 2)
const expected = new Date(Date.now() - minutesToSubtract * 60 * 1000)
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})

it('handles the edge case of zero minutes', () => {
const now = new Date()
const result = getDateMinusMinutes(0)
expect(result.getTime()).toBeCloseTo(now.getTime(), 2)
const expected = new Date()
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})

it('handles the edge case of negative minutes', () => {
const now = new Date()
const minutesToSubtract = -5
const result = getDateMinusMinutes(minutesToSubtract)
const expected = new Date(now.getTime() - minutesToSubtract * 60 * 1000)
expect(result.getTime()).toBeCloseTo(expected.getTime(), 2)
const expected = new Date(Date.now() - minutesToSubtract * 60 * 1000)
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})
})

describe('getDatePlusSeconds()', () => {
it('returns the current date and time plus the specified seconds', () => {
const now = new Date()
const secondsToAdd = 5
const result = getDatePlusSeconds(secondsToAdd)
const expected = new Date(now.getTime() + secondsToAdd * 1000)
expect(result.getTime()).toBeCloseTo(expected.getTime(), 2)
const expected = new Date(Date.now() + secondsToAdd * 1000)
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})

it('handles the edge case of zero seconds', () => {
const now = new Date()
const result = getDatePlusSeconds(0)
expect(result.getTime()).toBeCloseTo(now.getTime(), 2)
const expected = new Date()
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})

it('handles the edge case of negative seconds', () => {
const now = new Date()
const secondsToAdd = -5
const result = getDatePlusSeconds(secondsToAdd)
const expected = new Date(now.getTime() + secondsToAdd * 1000)
expect(result.getTime()).toBeCloseTo(expected.getTime(), 2)
const expected = new Date(Date.now() + secondsToAdd * 1000)
expect(expected.getTime() - result.getTime()).toBeLessThanOrEqual(1)
})
})
13 changes: 6 additions & 7 deletions src/lib/utils/date.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
export function getDatePlusMinutes(minutes: number): Date {
const milliseconds = minutes * 60 * 1000
return new Date(new Date().getTime() + milliseconds)
export function getDatePlusMinutes(minuteOffset: number): Date {
const millisecondOffset = minuteOffset * 60 * 1000
return new Date(Date.now() + millisecondOffset)
}

export function getDateMinusMinutes(minutes: number): Date {
const milliseconds = minutes * 60 * 1000
return new Date(new Date().getTime() - milliseconds)
const millisecondsOffset = minutes * 60 * 1000
return new Date(Date.now() - millisecondsOffset)
}

export function getDatePlusSeconds(seconds: number): Date {
const milliseconds = seconds * 1000
return new Date(new Date().getTime() + milliseconds)
return new Date(Date.now() + seconds * 1000)
}
4 changes: 2 additions & 2 deletions src/routes/[lang]/(game)/play/GameChunkInfo.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang='ts'>
import Home from 'lucide-svelte/icons/home'
import House from 'lucide-svelte/icons/house'
import TreeDeciduous from 'lucide-svelte/icons/tree-deciduous'
import Waves from 'lucide-svelte/icons/waves'
import type { GameChunk } from '$lib/game/services/chunk/interface'
Expand All @@ -10,7 +10,7 @@

<div class='block'>
{#if type === 'VILLAGE'}
<Home />
<House />
{:else if type === 'FOREST'}
<TreeDeciduous />
{:else if type === 'LAKE'}
Expand Down
31 changes: 3 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5070,16 +5070,7 @@ string-argv@^0.3.1, string-argv@~0.3.2:
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6"
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -5122,14 +5113,7 @@ stringify-object@^3.2.1:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -5647,16 +5631,7 @@ word-wrap@^1.2.5:
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down

0 comments on commit 05b11f9

Please sign in to comment.