Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add reactive Date object to svelte/reactivity #10622

Merged
merged 2 commits into from Feb 23, 2024
Merged

Conversation

trueadm
Copy link
Contributor

@trueadm trueadm commented Feb 23, 2024

This adds a reactive Date object that can be used within Svelte 5. Idea originally from #10263.

<script>
	import { Date } from 'svelte/reactivity';

	let date = new Date('2024/02/23 15:00:00');
</script>

<div>getSeconds: {date.getSeconds()}</div>
<div>getMinutes: {date.getMinutes()}</div>
<div>getHours: {date.getHours()}</div>
<div>getTime: {date.getTime()}</div>
<div>toDateString: {date.toDateString()}</div>

<button onclick={() => {
	date.setSeconds(date.getSeconds() + 1);
}}>1 second</button>
<button onclick={() => {
	date.setMinutes(date.getMinutes() + 1);
}}>1 minute</button>
<button onclick={() => {
	date.setHours(date.getHours() + 1);
}}>1 hour</button>

Copy link

changeset-bot bot commented Feb 23, 2024

🦋 Changeset detected

Latest commit: 002fa11

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris merged commit f658ca0 into main Feb 23, 2024
8 checks passed
@Rich-Harris Rich-Harris deleted the reactive-date branch February 23, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants