PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/view/dates/timeUntilInWords.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 155 lines | 137 code | 18 blank | 0 comment | 0 complexity | 1f64024c95df78685e446187c5ff5079 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cfcomponent extends="wheelsMapping.Test">
  2. <cffunction name="setup">
  3. <cfset loc.controller = controller(name="dummy")>
  4. <cfset loc.now = now()>
  5. <cfset loc.args = {}>
  6. <cfset loc.args.includeSeconds = true>
  7. <cfset loc.args.fromTime = loc.now>
  8. </cffunction>
  9. <cffunction name="test_with_seconds_below_5_seconds">
  10. <cfset loc.c = 5 - 1>
  11. <cfset loc.args.toTime = dateadd('s', loc.c, loc.now)>
  12. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  13. <cfset loc.r = "less than 5 seconds">
  14. <cfset assert("loc.e eq loc.r")>
  15. </cffunction>
  16. <cffunction name="test_with_seconds_below_10_seconds">
  17. <cfset loc.c = 10 - 1>
  18. <cfset loc.args.toTime = dateadd('s', loc.c, loc.now)>
  19. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  20. <cfset loc.r = "less than 10 seconds">
  21. <cfset assert("loc.e eq loc.r")>
  22. </cffunction>
  23. <cffunction name="test_with_seconds_below_20_seconds">
  24. <cfset loc.c = 20 - 1>
  25. <cfset loc.args.toTime = dateadd('s', loc.c, loc.now)>
  26. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  27. <cfset loc.r = "less than 20 seconds">
  28. <cfset assert("loc.e eq loc.r")>
  29. </cffunction>
  30. <cffunction name="test_with_seconds_below_40_seconds">
  31. <cfset loc.c = 40 - 1>
  32. <cfset loc.args.toTime = dateadd('s', loc.c, loc.now)>
  33. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  34. <cfset loc.r = "half a minute">
  35. <cfset assert("loc.e eq loc.r")>
  36. </cffunction>
  37. <cffunction name="test_with_seconds_below_60_seconds">
  38. <cfset loc.c = 60 - 1>
  39. <cfset loc.args.toTime = dateadd('s', loc.c, loc.now)>
  40. <cfset debug('loc.args', false)>
  41. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  42. <cfset loc.r = "less than a minute">
  43. <cfset assert("loc.e eq loc.r")>
  44. </cffunction>
  45. <cffunction name="test_with_seconds_above_60_seconds">
  46. <cfset loc.c = 60 + 50>
  47. <cfset loc.args.toTime = dateadd('s', loc.c, loc.now)>
  48. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  49. <cfset loc.r = "1 minute">
  50. <cfset assert("loc.e eq loc.r")>
  51. </cffunction>
  52. <cffunction name="test_without_seconds_above_60_seconds">
  53. <cfset loc.args.includeSeconds = false>
  54. <cfset loc.c = 60 + 50>
  55. <cfset loc.args.toTime = dateadd('s', loc.c, loc.now)>
  56. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  57. <cfset loc.r = "1 minute">
  58. <cfset assert("loc.e eq loc.r")>
  59. </cffunction>
  60. <cffunction name="test_without_seconds_below_45_minutes">
  61. <cfset loc.args.includeSeconds = false>
  62. <cfset loc.c = 45 - 1>
  63. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  64. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  65. <cfset loc.r = "#loc.c# minutes">
  66. <cfset assert("loc.e eq loc.r")>
  67. </cffunction>
  68. <cffunction name="test_without_seconds_below_90_minutes">
  69. <cfset loc.args.includeSeconds = false>
  70. <cfset loc.c = 90 - 1>
  71. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  72. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  73. <cfset loc.r = "about 1 hour">
  74. <cfset assert("loc.e eq loc.r")>
  75. </cffunction>
  76. <cffunction name="test_without_seconds_below_1440_minutes">
  77. <cfset loc.args.includeSeconds = false>
  78. <cfset loc.c = 1440 - 1>
  79. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  80. <cfset loc.c = Ceiling(loc.c/60)>
  81. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  82. <cfset loc.r = "about #loc.c# hours">
  83. <cfset assert("loc.e eq loc.r")>
  84. </cffunction>
  85. <cffunction name="test_without_seconds_below_2880_minutes">
  86. <cfset loc.args.includeSeconds = false>
  87. <cfset loc.c = 2880 - 1>
  88. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  89. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  90. <cfset loc.r = "1 day">
  91. <cfset assert("loc.e eq loc.r")>
  92. </cffunction>
  93. <cffunction name="test_without_seconds_below_43200_minutes">
  94. <cfset loc.args.includeSeconds = false>
  95. <cfset loc.c = 43200 - 1>
  96. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  97. <cfset loc.c = Int(loc.c/1440)>
  98. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  99. <cfset loc.r = "#loc.c# days">
  100. <cfset assert("loc.e eq loc.r")>
  101. </cffunction>
  102. <cffunction name="test_without_seconds_below_86400_minutes">
  103. <cfset loc.args.includeSeconds = false>
  104. <cfset loc.c = 86400 - 1>
  105. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  106. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  107. <cfset loc.r = "about 1 month">
  108. <cfset assert("loc.e eq loc.r")>
  109. </cffunction>
  110. <cffunction name="test_without_seconds_below_525600_minutes">
  111. <cfset loc.args.includeSeconds = false>
  112. <cfset loc.c = 525600 - 1>
  113. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  114. <cfset loc.c = Int(loc.c/43200)>
  115. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  116. <cfset loc.r = "#loc.c# months">
  117. <cfset assert("loc.e eq loc.r")>
  118. </cffunction>
  119. <cffunction name="test_without_seconds_below_1051200_minutes">
  120. <cfset loc.args.includeSeconds = false>
  121. <cfset loc.c = 1051200 - 1>
  122. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  123. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  124. <cfset loc.r = "almost 2 years">
  125. <cfset assert("loc.e eq loc.r")>
  126. </cffunction>
  127. <cffunction name="test_without_seconds_above_1051200_minutes">
  128. <cfset loc.args.includeSeconds = false>
  129. <cfset loc.c = 1051200>
  130. <cfset loc.c = (loc.c * 3) + 786>
  131. <cfset loc.args.toTime = dateadd('n', loc.c, loc.now)>
  132. <cfset loc.c = Int(loc.c/525600)>
  133. <cfset loc.e = loc.controller.timeUntilInWords(argumentCollection=loc.args)>
  134. <cfset loc.r = "over #loc.c# years">
  135. <cfset assert("loc.e eq loc.r")>
  136. </cffunction>
  137. </cfcomponent>