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

[Component] [calendar] Calendar 日历 每周第一天始终是周日,修改语言环境无效 #10200

Closed
cjbtd opened this issue Oct 24, 2022 · 11 comments

Comments

@cjbtd
Copy link

cjbtd commented Oct 24, 2022

Bug Type: Component

Environment

  • Vue Version: 3.2.41
  • Element Plus Version: 2.2.19
  • Browser / OS: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
  • Build Tool: Vite

Reproduction

Related Component

  • el-calendar

Reproduction Link

Github Repo

Steps to reproduce

设置firstDayOfWeek值的代码,是否应该在dayjs().locale(lang.value)这行代码后面?

What is Expected?

每周第一天是周一

What is actually happening?

每周第一天是周日

Additional comments

设置firstDayOfWeek值是否应该在dayjs().locale(lang.value)这行代码后面

@chenxch
Copy link
Member

chenxch commented Oct 24, 2022

这个应该是计算机基础知识的问题了,程序上每周的第一天是默认周日的,如果你有需要设置为星期一可以加一天。至于为什么时候周日你可以查阅相关资料。

@chenxch chenxch closed this as completed Oct 24, 2022
@cjbtd
Copy link
Author

cjbtd commented Oct 24, 2022

@chenxch 这不是代码BUG吗?我设置语言环境为中文应该默认每周第一天是周一,无需你说的【如果你有需要设置为星期一可以加一天】,日期选择组件显示是正常的,每周第一天是周一

@cjbtd cjbtd changed the title [Component] [calendar] Calendar 日历 每周第一天始终是周日 [Component] [calendar] Calendar 日历 每周第一天始终是周日,修改语言环境无效 Oct 24, 2022
@chenxch chenxch reopened this Oct 24, 2022
@tolking
Copy link
Member

tolking commented Oct 24, 2022

每周的第一天是周日,即使是设置中文环境。如果需要请自行修改 Demo

@tolking tolking closed this as completed Oct 24, 2022
@cjbtd
Copy link
Author

cjbtd commented Oct 24, 2022

@tolking 我的项目是多语言切换的,英文每周第一天是周日,中文是周一,请先确认这行代码是否有问题firstDayOfWeek,是否应该在const now = dayjs().locale(lang.value)这行代码下面

@cjbtd
Copy link
Author

cjbtd commented Oct 24, 2022

问题能解决,但Bug依旧存在,设置dayjs.en.weekStart只是妥协方法

import "element-plus/theme-chalk/display.css";
import "element-plus/theme-chalk/index.css";
import "element-plus/theme-chalk/dark/css-vars.css";

import type { App } from "vue";

import * as ElIcons from "@element-plus/icons-vue";
import ElementPlus, { dayjs } from "element-plus";
import enEle from "element-plus/es/locale/lang/en";
import zhEle from "element-plus/es/locale/lang/zh-cn";

import { isZh } from "~/utils";

// @ts-ignore
dayjs.en.weekStart = isZh() ? 1 : 0;

export default function (app: App) {
  for (const name in ElIcons) {
    app.component(name, (ElIcons as any)[name]);
  }

  app.use(ElementPlus, { locale: isZh() ? zhEle : enEle });
}

@chenxch
Copy link
Member

chenxch commented Oct 24, 2022

@tolking 我的项目是多语言切换的,英文每周第一天是周日,中文是周一,请先确认这行代码是否有问题firstDayOfWeek,是否应该在const now = dayjs().locale(lang.value)这行代码下面

一样的,你也是要去修改weekStart的

@cjbtd
Copy link
Author

cjbtd commented Oct 24, 2022

@tolking 我的项目是多语言切换的,英文每周第一天是周日,中文是周一,请先确认这行代码是否有问题firstDayOfWeek,是否应该在const now = dayjs().locale(lang.value)这行代码下面

一样的,你也是要去修改weekStart的

DatePicker 日期选择器 这个组件是无需修改weekStart的,它跟随locale,文档写的也是通过国际化来配置,我理解是无需设置weekStart

@chenxch
Copy link
Member

chenxch commented Oct 24, 2022

导入这个即可

import 'dayjs/locale/zh-cn'

@martonx
Copy link

martonx commented Nov 7, 2022

Hi, Could you summarize this thread in English please! I would like to set first day of week. Thank you very much!

@chenxch
Copy link
Member

chenxch commented Nov 7, 2022

Hi, Could you summarize this thread in English please! I would like to set first day of week. Thank you very much!

Option One:

main.js/ts

import 'dayjs/locale/hu'

Option Two:

demo
You can manually set weekStart.

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

此 issue 已被自动锁定,因为关闭后没有任何近期活动。如果有相关 bug,请重新创建一个新 issue。

@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants