Skip to content

Can't get relative time with locale #34

@fredt34

Description

@fredt34

I installed Svelte with bun, it uses recent versions:

    "@sveltejs/adapter-auto": "^2.1.1",
    "@sveltejs/kit": "^1.27.3",
    "flowbite-svelte": "^0.44.19",
    "svelte": "^4.2.2",
    "svelte-check": "^3.5.2",
    "svelte-time": "^0.8.0",
    "vite": "^4.5.0"

It runs in a lxd container.

I created this test pages +page.svelte to test various cases:

  • Time is Ok
  • relative is Ok with standard language
  • Time displays the date correctly in another locale (case 3 - but only with a dayjs date), not with a regular date (case 4)
  • Last test to display a relative date in another locale triggers an Error 500
<script context="module">
    import "dayjs/esm/locale/uk"
    import dayjs from "dayjs/esm"

    dayjs.locale("uk") // Ukrainian locale to be sure

</script>

<script>js
    import Time from "svelte-time"

    let djsDate = dayjs()
    let djsDateFormatted = dayjs().format("DD MMMM YY")
</script>

ok <Time timestamp="2020-01-01" /><br />
ok <Time relative timestamp="2020-01-01" /><br />
ok <Time timestamp={dayjs("2020-01-01")} format="MMMM" /><br />
oko? <Time timestamp="2020-01-01" format="MMMM" /><br />
ko 
<!-- <Time relative timestamp={dayjs("2020-01-01")} format="MMMM" /><br /> -->
<!-- TypeError: __vite_ssr_import_1__.dayjs(timestamp).from is not a function. (In '__vite_ssr_import_1__.dayjs(timestamp).from()', '__vite_ssr_import_1__.dayjs(timestamp).from' is undefined) -->

Last lines triggers a console error: TypeError: __vite_ssr_import_1__.dayjs(timestamp).from is not a function. (In '__vite_ssr_import_1__.dayjs(timestamp).from()', '__vite_ssr_import_1__.dayjs(timestamp).from' is undefined)

I'm quite starting tinkering with svelte and javascript, so I might have missed something obvious (or my config is too exotic ?)
All my other tests about Svelte / Kit are ok.

Plus, I'm a bit surprised that not every date applies the locale defined? Is a format really mandatory?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions