diff --git a/docs/en/Plugin.md b/docs/en/Plugin.md index ea3137b54..cc9688951 100644 --- a/docs/en/Plugin.md +++ b/docs/en/Plugin.md @@ -104,14 +104,18 @@ dayjs().format('Q Do k kk X x') List of added formats: -| Format | Output | Description | -| ------ | ---------------- | ---------------------------------- | -| `Q` | 1-4 | Quarter | -| `Do` | 1st 2nd ... 31st | Day of Month with ordinal | -| `k` | 1-24 | The hour, beginning at 1 | -| `kk` | 01-24 | The hour, 2-digits, beginning at 1 | -| `X` | 1360013296 | Unix Timestamp in second | -| `x` | 1360013296123 | Unix Timestamp in millisecond | +| Format | Output | Description | +| ------ | --------------------- | ----------------------------------------------------- | +| `Q` | 1-4 | Quarter | +| `Do` | 1st 2nd ... 31st | Day of Month with ordinal | +| `k` | 1-24 | The hour, beginning at 1 | +| `kk` | 01-24 | The hour, 2-digits, beginning at 1 | +| `X` | 1360013296 | Unix Timestamp in second | +| `x` | 1360013296123 | Unix Timestamp in millisecond | +| `w` | 1 2 ... 52 53 | Week of year (depend: weekOfYear plugin) | +| `ww` | 01 02 ... 52 53 | Week of year, 2-digits (depend: weekOfYear plugin) | +| `wo` | 1st 2nd ... 52nd 53rd | Week of year with ordinal (depend: weekOfYear plugin) | +| `gggg` | 2017 | Week Year (depend: weekYear plugin) | ### LocalizedFormat diff --git a/docs/es-es/Plugin.md b/docs/es-es/Plugin.md index c9be78736..7d44c3ad9 100644 --- a/docs/es-es/Plugin.md +++ b/docs/es-es/Plugin.md @@ -104,14 +104,18 @@ dayjs().format('Q Do k kk X x') Lista de formatos añadidos: -| Formato | Salida | Descripción | -| ------- | ------------- | ------------------------------------- | -| `Q` | 1-4 | Cuarto | -| `Do` | 1º 2º ... 31º | Día del mes con ordinal | -| `k` | 1-24 | Hora, contando desde 1 | -| `kk` | 01-24 | Hora, con 2 dígitos, contando desde 1 | -| `X` | 1360013296 | Tiempo Unix en segundos | -| `x` | 1360013296123 | Tiempo Unix en milisegundos | +| Formato | Salida | Descripción | +| ------- | --------------------- | ----------------------------------------------------- | +| `Q` | 1-4 | Cuarto | +| `Do` | 1º 2º ... 31º | Día del mes con ordinal | +| `k` | 1-24 | Hora, contando desde 1 | +| `kk` | 01-24 | Hora, con 2 dígitos, contando desde 1 | +| `X` | 1360013296 | Tiempo Unix en segundos | +| `x` | 1360013296123 | Tiempo Unix en milisegundos | +| `w` | 1 2 ... 52 53 | Week of year (depend: weekOfYear plugin) | +| `ww` | 01 02 ... 52 53 | Week of year, 2-digits (depend: weekOfYear plugin) | +| `wo` | 1st 2nd ... 52nd 53rd | Week of year with ordinal (depend: weekOfYear plugin) | +| `gggg` | 2017 | Week Year (depend: weekYear plugin) | ### LocalizedFormat diff --git a/docs/ja/Plugin.md b/docs/ja/Plugin.md index ab81c1f34..d0f4a7a23 100644 --- a/docs/ja/Plugin.md +++ b/docs/ja/Plugin.md @@ -104,14 +104,18 @@ dayjs().format('Q Do k kk X x') 追加されるフォーマットの一覧: -| フォーマット | 出力 | 説明 | -| ------------ | ---------------- | ---------------------------- | -| `Q` | 1-4 | 四半期 | -| `Do` | 1st 2nd ... 31st | 序数付きの日 | -| `k` | 1-24 | 1 始まりの時間 | -| `kk` | 01-24 | 1 始まりで 2 桁の時間 | -| `X` | 1360013296 | Unix タイムスタンプ (秒) | -| `x` | 1360013296123 | Unix タイムスタンプ (ミリ秒) | +| フォーマット | 出力 | 説明 | +| ------------ | --------------------- | ----------------------------------------------------- | +| `Q` | 1-4 | 四半期 | +| `Do` | 1st 2nd ... 31st | 序数付きの日 | +| `k` | 1-24 | 1 始まりの時間 | +| `kk` | 01-24 | 1 始まりで 2 桁の時間 | +| `X` | 1360013296 | Unix タイムスタンプ (秒) | +| `x` | 1360013296123 | Unix タイムスタンプ (ミリ秒) | +| `w` | 1 2 ... 52 53 | Week of year (depend: weekOfYear plugin) | +| `ww` | 01 02 ... 52 53 | Week of year, 2-digits (depend: weekOfYear plugin) | +| `wo` | 1st 2nd ... 52nd 53rd | Week of year with ordinal (depend: weekOfYear plugin) | +| `gggg` | 2017 | Week Year (depend: weekYear plugin) | ### LocalizedFormat diff --git a/docs/ko/Plugin.md b/docs/ko/Plugin.md index 368e3ba5f..dba61fdc6 100644 --- a/docs/ko/Plugin.md +++ b/docs/ko/Plugin.md @@ -104,14 +104,18 @@ dayjs().format('Q Do k kk X x') 추가된 형식 목록: -| Format | Output | Description | -| ------ | ---------------- | ---------------------------- | -| `Q` | 1-4 | 분기 | -| `Do` | 1st 2nd ... 31st | 서수형식의 일자 명 | -| `k` | 1-24 | 시간, 1부터 시작 | -| `kk` | 01-24 | 시간, 2자리 표현, 1부터 시작 | -| `X` | 1360013296 | 유닉스 타임스템프, 초 | -| `x` | 1360013296123 | 유닉스 타임스탬프, 밀리 초 | +| Format | Output | Description | +| ------ | --------------------- | ----------------------------------------------------- | +| `Q` | 1-4 | 분기 | +| `Do` | 1st 2nd ... 31st | 서수형식의 일자 명 | +| `k` | 1-24 | 시간, 1부터 시작 | +| `kk` | 01-24 | 시간, 2자리 표현, 1부터 시작 | +| `X` | 1360013296 | 유닉스 타임스템프, 초 | +| `x` | 1360013296123 | 유닉스 타임스탬프, 밀리 초 | +| `w` | 1 2 ... 52 53 | Week of year (depend: weekOfYear plugin) | +| `ww` | 01 02 ... 52 53 | Week of year, 2-digits (depend: weekOfYear plugin) | +| `wo` | 1st 2nd ... 52nd 53rd | Week of year with ordinal (depend: weekOfYear plugin) | +| `gggg` | 2017 | Week Year (depend: weekYear plugin) | ### LocalizedFormat diff --git a/docs/pt-br/Plugin.md b/docs/pt-br/Plugin.md index 2c2b3a068..22ebe9e8a 100644 --- a/docs/pt-br/Plugin.md +++ b/docs/pt-br/Plugin.md @@ -104,14 +104,18 @@ dayjs().format('Q Do k kk X x') Lista de formatos adicionados: -| Formato | Saída | Descrição | -| ------- | ---------------- | ------------------------------------ | -| `Q` | 1-4 | Quarter | -| `Do` | 1st 2nd ... 31st | Dia do mês com ordinal | -| `k` | 1-24 | Hora (começando do 1) | -| `kk` | 01-24 | Hora, com 2 dígitos (começando do 1) | -| `X` | 1360013296 | Unix Timestamp em segundos | -| `x` | 1360013296123 | Unix Timestamp em milissegundos | +| Formato | Saída | Descrição | +| ------- | --------------------- | ----------------------------------------------------- | +| `Q` | 1-4 | Quarter | +| `Do` | 1st 2nd ... 31st | Dia do mês com ordinal | +| `k` | 1-24 | Hora (começando do 1) | +| `kk` | 01-24 | Hora, com 2 dígitos (começando do 1) | +| `X` | 1360013296 | Unix Timestamp em segundos | +| `x` | 1360013296123 | Unix Timestamp em milissegundos | +| `w` | 1 2 ... 52 53 | Week of year (depend: weekOfYear plugin) | +| `ww` | 01 02 ... 52 53 | Week of year, 2-digits (depend: weekOfYear plugin) | +| `wo` | 1st 2nd ... 52nd 53rd | Week of year with ordinal (depend: weekOfYear plugin) | +| `gggg` | 2017 | Week Year (depend: weekYear plugin) | ### LocalizedFormat diff --git a/docs/zh-cn/Plugin.md b/docs/zh-cn/Plugin.md index c50f5fd4e..57838c742 100644 --- a/docs/zh-cn/Plugin.md +++ b/docs/zh-cn/Plugin.md @@ -103,14 +103,18 @@ dayjs().format('Q Do k kk X x') 扩展的模版列表: -| 模版 | 输出 | 简介 | -| ---- | ---------------- | ---------------------- | -| `Q` | 1-4 | 季度 | -| `Do` | 1st 2nd ... 31st | 带序号的月份 | -| `k` | 1-24 | 时:由 1 开始 | -| `kk` | 01-24 | 时:由 1 开始,二位数 | -| `X` | 1360013296 | 秒为单位的 Unix 时间戳 | -| `x` | 1360013296123 | 毫秒单位的 Unix 时间戳 | +| 模版 | 输出 | 简介 | +| ------ | --------------------- | ------------------------------------------ | +| `Q` | 1-4 | 季度 | +| `Do` | 1st 2nd ... 31st | 带序号的月份 | +| `k` | 1-24 | 时:由 1 开始 | +| `kk` | 01-24 | 时:由 1 开始,二位数 | +| `X` | 1360013296 | 秒为单位的 Unix 时间戳 | +| `x` | 1360013296123 | 毫秒单位的 Unix 时间戳 | +| `w` | 1 2 ... 52 53 | 年中第几周 (依赖: weekOfYear 插件) | +| `ww` | 01 02 ... 52 53 | 年中第几周,二位数 (依赖: weekOfYear 插件) | +| `wo` | 1st 2nd ... 52nd 53rd | 带序号的年中第几周 (依赖: weekOfYear 插件) | +| `gggg` | 2017 | 根据周计算的年份 (依赖: weekYear 插件) | ### LocalizedFormat diff --git a/src/plugin/advancedFormat/index.js b/src/plugin/advancedFormat/index.js index 117831b8d..c7a037015 100644 --- a/src/plugin/advancedFormat/index.js +++ b/src/plugin/advancedFormat/index.js @@ -13,7 +13,7 @@ export default (o, c, d) => { // locale needed later const locale = this.$locale() const utils = this.$utils() const str = formatStr || FORMAT_DEFAULT - const result = str.replace(/\[([^\]]+)]|Q|wo|gggg|Do|X|x|k{1,2}|S/g, (match) => { + const result = str.replace(/\[([^\]]+)]|Q|wo|ww|w|gggg|Do|X|x|k{1,2}|S/g, (match) => { switch (match) { case 'Q': return Math.ceil((this.$M + 1) / 3) @@ -23,6 +23,9 @@ export default (o, c, d) => { // locale needed later return this.weekYear() case 'wo': return locale.ordinal(this.week(), 'W') // W for week + case 'w': + case 'ww': + return utils.s(this.week(), match === 'w' ? 1 : 2, '0') case 'k': case 'kk': return utils.s(String(this.$H === 0 ? 24 : this.$H), match === 'k' ? 1 : 2, '0') diff --git a/test/plugin/weekOfYear.test.js b/test/plugin/weekOfYear.test.js index 30adf6df8..a0c446a86 100644 --- a/test/plugin/weekOfYear.test.js +++ b/test/plugin/weekOfYear.test.js @@ -2,8 +2,10 @@ import moment from 'moment' import MockDate from 'mockdate' import dayjs from '../../src' import weekOfYear from '../../src/plugin/weekOfYear' +import advancedFormat from '../../src/plugin/advancedFormat' import '../../src/locale/en-gb' +dayjs.extend(advancedFormat) dayjs.extend(weekOfYear) beforeEach(() => { @@ -39,3 +41,10 @@ it('Week of year with locale', () => { expect(dayjs('2018-12-30').week()).toBe(moment('2018-12-30').week()) expect(dayjs('2019-12-29').week()).toBe(moment('2019-12-29').week()) }) + +it('Format w ww wo', () => { + const day = '2019-07-28' + const D = dayjs(day) + const M = moment(day) + expect(D.format('w ww wo')).toBe(M.format('w ww wo')) +})