|
起因:看到这个我为 Windows 10 修复了一个 bug,我就看看我的Win7计算器有什么表现。
Windows的计算器BUG不知道发现了多少了,比一般专写BUG的程序员写的BUG还多还隐蔽
更NB的是,Win10的计算器是开源的,源代码的逻辑实在是看不懂,堪称简单问题复杂化的典范,可以作为我辈楷模,以后我们也要写这种又臭又烂还有隐藏BUG的代码。
计算日期间隔(请查看差(年、月、周、天)),我的版本是6.1.7601,不知道其他版本有没有这个问题:
其他三个都没有问题,就是下面这个,呵呵呵呵。
然后看看bug10关于日期之差的计算:- DateDifference calculate_difference(start_date, end_date) {
- uint[] diff_types = [year, month, week, day]
- uint[] typical_days_in_type = [365, 31, 7, 1]
- uint[] calculated_difference = [0, 0, 0, 0]
- date temp_pivot_date
- date pivot_date = start_date
- uint days_diff = calculate_days_difference(start_date, end_date)
- for(type in differenceTypes) {
- temp_pivot_date = pivot_date
- uint current_guess = days_diff /typicalDaysInType[type]
- if(current_guess !=0)
- pivot_date = advance_date_by(pivot_date, type, current_guess)
-
- int diff_remaining
- bool best_guess_hit = false
- do{
- diff_remaining = calculate_days_difference(pivot_date, end_date)
- if(diff_remaining < 0) {
- // pivotDate has gone over the end date; start from the beginning of this unit
- current_guess = current_guess - 1
- pivot_date = temp_pivot_date
- pivot_date = advance_date_by(pivot_date, type, current_guess)
- best_guess_hit = true
- } else if(diff_remaining > 0) {
- // pivot_date is still below the end date
- if(best_guess_hit)
- break;
- current_guess = current_guess + 1
- pivot_date = advance_date_by(pivot_date, type, 1)
- }
- } while(diff_remaining!=0)
- temp_pivot_date = advance_date_by(temp_pivot_date, type, current_guess)
- pivot_date = temp_pivot_date
- calculated_difference[type] = current_guess
- days_diff = calculate_days_difference(pivot_date, end_date)
- }
- calculcated_difference[day] = days_diff
- return calculcated_difference
- }
复制代码 反正我才疏学浅,只会把两个日期直接相减,惭愧。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|