From 234da67b0d8fc828f797b930b403d32975e7ed33 Mon Sep 17 00:00:00 2001 From: 6tail <6tail@6tail.cn> Date: Thu, 4 Aug 2022 21:47:09 +0800 Subject: [PATCH] =?UTF-8?q?v1.2.33=20=E4=BF=AE=E5=A4=8DSolarWeek=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=B7=A8=E6=9C=88=E5=A4=A9=E4=B8=BANaN=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/Solar.test.js | 10 +++++++++ __tests__/SolarMonth.test.js | 38 ++++++++++++++++++++++++++++------- __tests__/SolarSeason.test.js | 14 ++++++------- lunar.js | 17 ++++++++++++++-- package.json | 5 ++--- 5 files changed, 65 insertions(+), 19 deletions(-) diff --git a/__tests__/Solar.test.js b/__tests__/Solar.test.js index 446fd50..a935ca7 100644 --- a/__tests__/Solar.test.js +++ b/__tests__/Solar.test.js @@ -46,3 +46,13 @@ test('13', () => { var solar = Solar.fromYmd(1996, 3, 25); expect(solar.getFestivals() + '').toBe('全国中小学生安全教育日'); }); + +test('14', () => { + const solar = Solar.fromYmd(1583, 1, 13); + expect(solar.getLunar().toString()).toBe('一五八二年腊月二十'); +}); + +test('15', () => { + const solar = Solar.fromYmd(1583, 1, 14); + expect(solar.getLunar().toString()).toBe('一五八二年腊月廿一'); +}); diff --git a/__tests__/SolarMonth.test.js b/__tests__/SolarMonth.test.js index 6590007..3c3807d 100644 --- a/__tests__/SolarMonth.test.js +++ b/__tests__/SolarMonth.test.js @@ -1,13 +1,37 @@ -var {SolarSeason} = require('../lunar'); +var {SolarMonth} = require('../lunar'); test('toString()', () => { - const season = SolarSeason.fromYm(2019, 5); - expect(season.toString()).toBe('2019.2'); - expect(season.next(1).toString()).toBe('2019.3'); + const month = SolarMonth.fromYm(2019, 5); + expect(month.toString()).toBe('2019-5'); + expect(month.next(1).toString()).toBe('2019-6'); }); test('toFullString()', () => { - const season = SolarSeason.fromYm(2019, 5); - expect(season.toFullString()).toBe('2019年2季度'); - expect(season.next(1).toFullString()).toBe('2019年3季度'); + const month = SolarMonth.fromYm(2019, 5); + expect(month.toFullString()).toBe('2019年5月'); + expect(month.next(1).toFullString()).toBe('2019年6月'); +}); + +test('test1', () => { + const month = SolarMonth.fromYm(2022, 7); + const weeks = month.getWeeks(0); + const lastWeek = weeks[weeks.length - 1]; + const days = lastWeek.getDays(); + expect(days[0].toFullString()).toBe('2022-07-31 00:00:00 星期日 狮子座'); +}); + +test('test2', () => { + const month = SolarMonth.fromYm(2022, 7); + const weeks = month.getWeeks(0); + const lastWeek = weeks[weeks.length - 1]; + const days = lastWeek.getDays(); + expect(days[1].toFullString()).toBe('2022-08-01 00:00:00 星期一 (建军节) 狮子座'); +}); + +test('test3', () => { + const month = SolarMonth.fromYm(2022, 7); + const weeks = month.getWeeks(0); + const lastWeek = weeks[weeks.length - 1]; + const days = lastWeek.getDays(); + expect(days[6].toFullString()).toBe('2022-08-06 00:00:00 星期六 狮子座'); }); diff --git a/__tests__/SolarSeason.test.js b/__tests__/SolarSeason.test.js index 0940536..6590007 100644 --- a/__tests__/SolarSeason.test.js +++ b/__tests__/SolarSeason.test.js @@ -1,13 +1,13 @@ -var {SolarMonth} = require('../lunar'); +var {SolarSeason} = require('../lunar'); test('toString()', () => { - const month = SolarMonth.fromYm(2019, 5); - expect(month.toString()).toBe('2019-5'); - expect(month.next(1).toString()).toBe('2019-6'); + const season = SolarSeason.fromYm(2019, 5); + expect(season.toString()).toBe('2019.2'); + expect(season.next(1).toString()).toBe('2019.3'); }); test('toFullString()', () => { - const month = SolarMonth.fromYm(2019, 5); - expect(month.toFullString()).toBe('2019年5月'); - expect(month.next(1).toFullString()).toBe('2019年6月'); + const season = SolarSeason.fromYm(2019, 5); + expect(season.toFullString()).toBe('2019年2季度'); + expect(season.next(1).toFullString()).toBe('2019年3季度'); }); diff --git a/lunar.js b/lunar.js index b7ad239..236848e 100644 --- a/lunar.js +++ b/lunar.js @@ -1945,9 +1945,22 @@ }, getWeeks:function(start){ var l = []; - var weeks = SolarUtil.getWeeksOfMonth(this._p.year,this._p.month,start); + var cy = this._p.year; + var cm = this._p.month; + var weeks = SolarUtil.getWeeksOfMonth(cy, cm, start); + var days = SolarUtil.getDaysOfMonth(cy, cm); for(var i = 0;i days) { + d -= days; + m++; + if (m > 12) { + y++; + } + } + l.push(SolarWeek.fromYmd(y, m, d, start)); } return l; }, diff --git a/package.json b/package.json index 484562b..9e83f30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lunar-javascript", - "version": "1.2.32", + "version": "1.2.33", "description": "lunar is a calendar library for Solar and Chinese Lunar.", "main": "index.js", "scripts": { @@ -50,6 +50,5 @@ "homepage": "https://github.com/6tail/lunar-javascript", "devDependencies": { "jest": "^26.6.3" - }, - "dependencies": {} + } }