![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 12:37 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » [Challenge 5]: Calculation of Time Before and After a Date [Difficulty: ☆☆] |
| Printable Version 5,303 / 27 |
| Floor1 flyinspace | Posted 2007-05-01 07:17 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
Goal: After entering any date, calculate the time period before or after this date.
For example: Date 2007-03-31 3 is to query the date 3 days later. Language requirements for writing: cmd (commands included in help) vbs (no cdate-like functions can be used, no system API functions can be called), no temporary files can be generated. Limitations: No third-party tools can be used Target audience: Those who have learned batch processing but haven't been able to apply it flexibly. I hope these people can quickly learn the calculation skills of batch processing through these examples.. Difficulty: Nested variables, addition and subtraction of dates, use of command line parameters (no parameter detection is required), overflow handling of different sizes of values. Target points: 1 point for completing each item, 4 points for completing all four items or 4 points. ps: Points are not the goal.. The important thing is that we can complete such challenges. Please everyone do your best to write according to your ability: ) ________________________________________________________ The next issue of the topic will be launched every Monday. Our challenges will gradually increase in difficulty, please do it according to your ability. Personal code is on the first floor. ———————————————————————————————————— Download of part of the content of the first three issues of the challenge [ Last edited by flyinspace on 2007-4-30 at 06:29 PM ] Attachments 挑战.rar (4.02 KiB) |
|
| Floor2 flyinspace | Posted 2007-05-01 07:18 |
| 银牌会员 Posts 517 Credits 1,206 | |
Found some bugs. .. Will rewrite it in a few days. .. youxi 01 and slore have better ones. Welcome everyone's use and testing. [ Last edited by flyinspace on 2007-5-2 at 08:28 AM ] |
|
| Floor3 lxmxn | Posted 2007-05-01 07:39 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Re flyinspace:
Tested it and found the following problems and put forward some suggestions 1、 For example: Date 2007-03-31 3 is to query the date 3 days later. The script name has the same name as the system internal command "Date", which causes the system date to be directly changed during testing. It is recommended to modify it to a script name like "Datex"; 2、For the date format like "2007-3-28", it cannot be detected and processed normally. It is recommended to add a detection and processing mechanism; 3、In addition, put forward a suggestion. When sending more code, try to enclose the code with to facilitate others to view and copy. [ Last edited by lxmxn on 2007-4-30 at 06:40 PM ] |
|
| Floor4 slore | Posted 2007-05-01 17:05 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
CDATE can't be used, sigh~ Does it need to be complicated? Then treat it as a string processing.
[ Last edited by slore on 2007-5-1 at 04:28 AM ] |
|
| Floor5 baomaboy | Posted 2007-05-01 18:02 |
| 银牌会员 Posts 554 Credits 1,513 | |
|
It's really like that. There's a simple method but can't be used. I most admire the conciseness of兄's code.
|
|
| Floor6 slore | Posted 2007-05-01 18:50 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
vbs:
execute("msgbox #2007-03-31#+3") |
|
| Floor7 baomaboy | Posted 2007-05-01 20:32 |
| 银牌会员 Posts 554 Credits 1,513 | |
Originally posted by slore at 2007-5-1 18:50: This is well used, avoiding functions and using #. Haha, wonderful |
|
| Floor8 zh159 | Posted 2007-05-01 23:34 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
vbs (No use of functions like cdate, no calling of system API functions) It feels like it's saying: No use of fuels like gasoline, how do you start a car |
|
| Floor9 flyinspace | Posted 2007-05-02 13:53 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
Oh.. What I originally meant was just to use VBS to write a class by myself..
For example: class xdata { int Year; int Month; int Day; AddDay(); …… }; Something similar to this function...... Who knew that someone came up with another way.. (Roughly looked at the VBS tutorial. It seems that VBS can write its own classes..) |
|
| Floor10 flyinspace | Posted 2007-05-02 13:54 |
| 银牌会员 Posts 517 Credits 1,206 | |
Originally posted by zh159 at 2007-5-1 10:34 AM: |
|
| Floor11 slore | Posted 2007-05-02 17:12 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
VBS can write classes:
Haha, but I don't know how to apply the class... P is too slow, tried calculating 8000 days directly..... |
|
| Floor12 flyinspace | Posted 2007-05-02 17:20 |
| 银牌会员 Posts 517 Credits 1,206 | |
Originally posted by slore at 2007-5-2 04:12 AM: Thanks for pointing out the problem... In the next version, the query days problem will be judged.. So it can calculate the fastest. For days greater than 30, subtract by months. For days greater than one year, judge whether it is a leap year and then subtract.. This can be much faster. |
|
| Floor13 youxi01 | Posted 2007-05-02 17:22 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
In fact, the old moderator willsort has already written the corresponding code. However, so far, I still haven't figured out the relevant calculation principle.
Using this code, the requirements related to the challenge question can be written. |
|
| Floor14 flyinspace | Posted 2007-05-02 17:34 |
| 银牌会员 Posts 517 Credits 1,206 | |
Originally posted by youxi01 at 2007-5-2 04:22 AM: The algorithm is very simple. .. It is also smarter than mine... But because the existence of leap years is not considered. .. Problems will occur when calculating longer days... If the judgment of leap years is added, it will be much better. |
|
| Floor15 youxi01 | Posted 2007-05-02 17:47 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
Didn't consider leap years, have you tested it?
Why does my test "feel" that it has already considered leap years?! In fact, it must have considered it. As for the calculation principle, I really don't know. |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |