置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Birthday

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
  1. local module = {}
  2. local getArgs = require('Module:Arguments').getArgs
  3. function module._main(args)
  4. args[1] = tonumber(args[1])
  5. args[2] = tonumber(args[2])
  6. -- 默认值暂时使用GMT,即不手动指定时区时维持原状;但也许改为UTC+8更合适?
  7. local time = os.time() + (tonumber(args.tz) or 0) * 3600
  8. local month = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  9. if args[1] < 1 or args[1] > 12 then
  10. error('请输入正确的月份!')
  11. end
  12. if args[2] < 1 or args[2] > month[args[1]] then
  13. error('请输入正确的日期!')
  14. end
  15. function isLeapYear(year)
  16. local year = year or os.date('%Y', time)
  17. if (year % 4 == 0) and (year % 100 ~= 0 or year % 400 == 0) then
  18. return true
  19. end
  20. return false
  21. end
  22. if isLeapYear() == false then
  23. month[2] = 28
  24. end
  25. local count = args[2]
  26. for i=1, args[1] - 1 do
  27. count = count + month[i]
  28. end
  29. local year = os.date('%Y', time) + 1
  30. local num = tonumber(os.date('%j', time))
  31. count = count - num
  32. if count < 0 then
  33. local foo = 0
  34. if isLeapYear(year) then
  35. if (args[1] == 2 and args[2] == 29) or args[1] > 2 then
  36. foo = 1
  37. end
  38. end
  39. count = count + 365 + foo
  40. end
  41. -- 针对2月29日的计算
  42. if(args[1] == 2 and args[2] == 29) then
  43. count = 0
  44. if isLeapYear() == false or num > 60 then
  45. local foo = 0
  46. if isLeapYear() and num > 60 then
  47. foo = 1
  48. end
  49. count = 365 - num + foo
  50. while isLeapYear(year) == false do
  51. count = count + 365
  52. year = year + 1
  53. end
  54. count = count + 60
  55. else
  56. count = 60 - num
  57. end
  58. end
  59. count = math.floor(count)
  60. return count
  61. end
  62. function module.main(frame)
  63. local args = getArgs(frame, {wrappers='Template:生日倒计时'})
  64. return module._main(args)
  65. end
  66. return module