China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 05:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] ********Simple Solar Terms Calendar******** View 2,216 Replies 17
Original Poster Posted 2007-09-29 16:01 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
@echo off
setlocal enabledelayedexpansion
::::::::Simple perpetual calendar {s11ss 2007-9-29}::::::::
::Principle: Find out what day of the week the first day of a certain month is, from which we can get what day of the week other days correspond to, and finally display each day by rows.
echo Please input a year and a month,like 2007-9:
echo.
set/p str=
for /f "delims=- tokens=1*" %%a in ('echo %str%') do (
set/a year=%%a
set/a month=%%b
if %%b leq 2 (set/a year-=1 && set/a month+=12)
set y=!year:~-2!
set is0=!y:~0,1!
if !is0! equ 0 set y=!y:~1,1!
set c=!year:~0,-2!
set m=!month!
set d=1
if %%b leq 2 (set/a year+=1 && set/a month-=12)
)
set/a w=(!y!+!y!/4+%c%/4-2*%c%+26*(%m%+1)/10+%d%-1)
::The above comes from Zeller's formula, which is the key to finding out what day of the week the 1st is.
set/a ?=!w!%%7
if !?! lss 0 set/a ?+=7
set/a r4=!year!%%4,r100=!year!%%100,r400=!year!%%400
set/a feb=28
if !r4! equ 0 (if not !r100! equ 0 set/a feb=29)
if !r400! equ 0 set/a feb=29
set/a mseq=1
for %%a in (31,!feb!,31,30,31,30,31,31,30,31,30,31) do (
if !mseq! equ !month! (set/a day=%%a && goto :e)
set/a mseq+=1
)
:e
set s1= 1
for /l %%a in (1,1,!?!) do set s1= !s1!
set/a row=1
set x=!s1!
for /l %%a in (2,1,!day!) do (
if %%a lss 10 (set dseq= %%a) else (set dseq=%%a)
set/a ?+=1
if !?! equ 7 (
set/a ?=0
set s!row!=!x!
set/a row+=1
set x=!dseq!
) else (
set x=!x! !dseq!
)
)
set s!row!=!x!
echo Sun Mon Tue Wed Thu Fri Sat
for /l %%a in (1,1,!row!) do echo !s%%a!
echo.
echo Press Any Key To Exit...
pause>nul
goto :eof
Zeller's Formula
Zeller's (Zeller) formula: is a formula for calculating the day of the week.
For any given date, you can use this formula to calculate what day of the week it is.

The Zeller formula is as follows:
w=y++-2c++d-1

The meanings of the symbols in the formula are as follows:
w: Day of the week; w modulo 7 gives: 0-Sunday, 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday
c: Century (first two digits)
y: Year (last two digits)
m: Month (m is greater than or equal to 3 and less than or equal to 14, that is, in Zeller's formula, January and February of a certain year should be regarded as the 13th and 14th months of the previous year. For example, January 1, 2003 should be regarded as January 1, 2002)
d: Day
represents taking the integer part, that is, only the integer part.

The following takes the 100th anniversary of the founding of the People's Republic of China (October 1, 2049) to calculate what day of the week it is. The process is as follows:
w=y++-2c++d-1
=49++-2×20++1-1
=49++5-40+
=49+12+5-40+28
=54 (remainder 5 when divided by 7)
That is, October 1, 2049 (100th anniversary of National Day) is Friday.

Another example: calculate April 4, 2006. The process is as follows:
w=y++-2c++d-1
=6++-2*20++4-1
=-12 (remainder 2 when divided by 7, pay attention to the modulo operation for negative numbers!)

However, the above formula is only suitable for the situation after October 15, 1582 (the 10th year of Wanli in the Ming Dynasty in China). Pope Gregory XIII of Rome organized a group of astronomers in 1582 to calculate data based on Copernicus' heliocentric theory and modified the Julian calendar. The 10 days between October 5 and 14, 1582 were declared void, and October 15 followed October 4.
Later, people called this new calendar the "Gregorian calendar", which is the calendar commonly used in the world today, referred to as the Gregorian calendar or the Gregorian calendar.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
wudixin96 +9 2007-09-29 16:12
Floor 2 Posted 2007-09-29 17:30 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
I also wrote one ~~~~~~~~~~~~~

@echo off
setlocal enabledelayedexpansion
:{
://Process months
set Y=%date:~0,4%
set M=%date:~5,2%
set D=%date:~8,2%
if %M:~0,1%==0 set M=%M:~1,1%
if %D:~0,1%==0 set D=%D:~1,1%
FOR %%i IN (4 400) DO (
set /a T1=%y%%%%%i
if !T1!==0 (set runnian=1) ELSE set runnian=0
)
call :checkmouth %runnian%
set T1=%Y:~0,2%
set T2=%Y:~2,2%
if %T2:~0,1%==0 set T2=%T2:~1,1%
set /a T1=%T1%%%4
set /a T1=T1/-2+5
set /a T2=((%T2%-%t2%%%4)/4+%T2%)%%7
call :yueyushu
set /a T4=(%T1%+%T2%+%T3%+1)%%7
rem T4=Week number, 0=>Sunday 1=>Monday ....
set T1=&set T2=&set T3=&set Y=
:}

:{
://Display preparation
call :setdateend %M%
set /a dateend=%dateend%+%T4%-1
set T1=1
for /L %%i IN (0,1,38) DO (
if %%i GEQ %T4% IF %%i LEQ %dateend% (
if !T1! LEQ 9 (set W%%i= !T1! ) ELSE set W%%i=!T1!
if !T1! EQU %D% set W%%i=!T1!*
call set T5=%%js9!T1!%%
if NOT "!T5!"=="" (
if !T1! LEQ 9 (set W%%i= !T1!$) ELSE set W%%i=!T1!$
if !T1! EQU %D% (
if !T1! LEQ 9 (set W%%i= !T1!#) ELSE set W%%i=!T1!#
)
)
set /a T1=!T1!+1
)
if %%i LSS %T4% set "W%%i= "
if %%i GTR %dateend% set "W%%i= "
)
set T1=
echo Today is: %date%
echo Sun Mon Tue Wed Thu Fri Sat
echo %W0% %W1% %W2% %W3% %W4% %W5% %W6%
echo %W7% %W8% %W9% %W10% %W11% %W12% %W13%
echo %W14% %W15% %W16% %W17% %W18% %W19% %W20%
echo %W21% %W22% %W23% %W24% %W25% %W26% %W27%
echo %W28% %W29% %W30% %W31% %W32% %W33% %W34%
echo %W35% %W36% %W37% %W38% 
GOTO :EOF
:}

:{
://Sub-block part
:setdateend
for %%i IN (1 3 5 7 8 10 12) DO (
if %1==%%i (set dateend=31) ELSE set dateend=30
)

if %1==2 (
If %runnian%==1 (set dateend=29) ELSE set dateend=28
)
GOTO :EOF
:yueyushu
set T3=!%m%y!
goto :EOF
:checkmouth
if %1==0 (
set 1y=1
set 2y=4
) ELSE (
set 1y=0
set 2y=3
)
set 3y=4
set 4y=0
set 5y=2
set 6y=5
set 7y=0
set 8y=3
set 9y=6
set 10y=1
set 11y=4
set 12y=8
GOTO :EOF
:}
Floor 3 Posted 2007-09-29 17:32 ·  中国 天津 电信
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
A showdown between experts, sparking intense interaction
Floor 4 Posted 2007-09-29 17:55 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
It's a pity that his method is much simpler than mine~~
Floor 5 Posted 2007-09-29 23:01 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by knoppix7 at 2007-9-29 05:55 PM:
It's a pity that his method is much simpler than mine~~


knoppix7, there seems to be a problem with your leap year judgment.
Do you mean that only those divisible by 400 are leap years?
You can test it with 2004-2-29.........2004 is obviously a leap year
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
knoppix7 +4 2007-09-30 16:46
Floor 6 Posted 2007-09-29 23:50 ·  中国 广西 桂林 荔浦市 电信
新手上路
Credits 4
Posts 2
Joined 2007-09-29 23:20
18-year member
UID 98602
Gender Male
Status Offline
Dizzy...
Floor 7 Posted 2007-09-29 23:50 ·  中国 广西 桂林 荔浦市 电信
新手上路
Credits 4
Posts 2
Joined 2007-09-29 23:20
18-year member
UID 98602
Gender Male
Status Offline
It's dizzying just looking at it, there are too many. I'm dizzy
Floor 8 Posted 2007-09-30 12:36 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Only divisible by 4 or 400.
Got it. The calculation program was wrong...
Need to change
FOR %%i IN (4 400) DO (
set /a T1=%y%%%%%i
if !T1!==0 (set runnian=1) ELSE set runnian=0
)


to
set runnian=0
FOR %%i IN (4 400) DO (
set /a T1=%y%%%%%i
if !T1!==0 (set runnian=1)
)

[ Last edited by knoppix7 on 2007-9-30 at 04:45 PM ]
Floor 9 Posted 2007-09-30 16:46 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
As a return for DEBUG. Add 4 points.
Floor 10 Posted 2007-09-30 17:23 ·  中国 北京 电信
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
knoppix7,
There is a problem with the algorithm you used to judge leap years. I used to be completely confused about judging leap years.

The statement "A year divisible by 4 or 400 is a leap year" is equivalent to saying that a year divisible by 4 is a leap year, because a number divisible by 400 is a sufficient condition for the number to be divisible by 4.

It's like saying: A woman with big eyes or a woman with big eyes and long hair is a beauty. Actually, it means that a woman with big eyes is a beauty.

The correct algorithm should be: A year divisible by 4 but not by 100 is a leap year; or a year divisible by 400 is a leap year.
For example, the year 2100 would be a leap year according to your algorithm, but actually it is not because it does not satisfy either of the above two conditions.

But actually, a year divisible by 3200 is not a leap year, but that's too far from now. Generally, the above algorithm is used to judge leap years.

I didn't understand the judgment of leap years when I studied C language a few years ago. I finally fully understood it when I wrote this perpetual calendar recently.
Floor 11 Posted 2007-09-30 17:31 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Actually, the statement that "what is divisible by 3200 is not a leap year" is too... Don't make it lead to the idea that the opposite is a leap year...

A year divisible by 4 but not by 100 is a leap year; or a year divisible by 400 is a leap year. This is correct.

Reason:
To determine which year in the solar calendar is a leap year, you just need to do a simple calculation. Divide the year of the solar calendar by 4. If it is divisible, it is a leap year. For example, 1964, 1968, etc., are all leap years, and February of these years has 29 days.
Also, because the actual number of days in a solar year is 365 days 5 hours 48 minutes 46 seconds, which is 5 hours 48 minutes 46 seconds more than the common year of 365 days. Over four years, it only adds up to 23 hours 15 minutes 4 seconds. If we add one day every 4 years for a leap year, we add an extra 44 minutes 56 seconds. In about 400 years, it will add about 3 days. So, we have set an additional rule: For years that are full centuries in the solar calendar, such as AD 1800, 1900, 2000, etc., only those divisible by 400 are considered leap years. Therefore, although AD 1800 and 1900 are divisible by 4, they are not divisible by 400, so they are not considered leap years, while AD 2000 is a leap year, and February of it has 29 days. With this additional rule, we can subtract those 3 extra days over 400 years. Although there will still be a slight error after such adjustment, it will take 3000 years to be off by one day, which is very accurate for our daily application.
Floor 12 Posted 2007-09-30 17:59 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Originally posted by s11ss at 2007-9-30 05:23 PM:
knoppix7,
Your algorithm for determining leap years is problematic. I also used to be confused about how to determine leap years.

The statement that "a year divisible by 4 or 400 is a leap year" is equivalent to saying that a year divisible by 4 is a leap year, because...


I'm sorry. I specifically copied the method from the internet. However, I noticed that the time in WXP doesn't reach the year 2100.
So I didn't include it.
Floor 13 Posted 2007-09-30 18:04 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
Originally posted by slore at 2007-9-30 05:31 PM:
Actually, the statement that "those divisible by 3200 are not leap years" is too... Don't make people think that the opposite is a leap year...

A leap year is divisible by 4 but not by 100, or divisible by 400...



What is the calculation method... There's no way to specify the time manually...
Floor 14 Posted 2007-09-30 18:07 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
I've got it.
Judge with the date command.
Example:
C:\Documents and Settings\lenovo>date 2007-02-29(Not a leap year, so...)
The system cannot accept the entered date.
Enter new date: (year month day)

C:\Documents and Settings\lenovo>date 2100-02-29(Exceeds the year limit of WXP)
The system cannot accept the entered date.
Enter new date: (year month day)


C:\Documents and Settings\lenovo>date 2004-02-29(Succeeds)

[ Last edited by knoppix7 on 2007-10-1 at 02:11 PM ]
Floor 15 Posted 2007-10-01 14:13 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
The method I thought of:
@echo off
set DD=%date:~0,10%
set runnian=0
date %y%-2-29|find "The system cannot accept the entered date." >nul ||set runnian=1
date %DD%

But I didn't test it...
Forum Jump: