PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/tests/view/dates/distanceOfTimeInWords.cfc

http://cfwheels.googlecode.com/
ColdFusion CFScript | 182 lines | 161 code | 21 blank | 0 comment | 0 complexity | 56140277e6f1545caa4f3747c41134bf MD5 | raw file
  1<cfcomponent extends="wheelsMapping.Test">
  2
  3	<cffunction name="setup">
  4		<cfset loc.controller = controller(name="dummy")>
  5		<cfset loc.f = "distanceOfTimeInWords">
  6		<cfset loc.args = {}>
  7		<cfset loc.args.fromTime = now()>
  8		<cfset loc.args.includeSeconds = true>
  9	</cffunction>
 10
 11	<cffunction name="test_with_seconds_below_5_seconds">
 12		<cfset loc.c = 5 - 1>
 13		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 14		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 15		<cfset loc.r = "less than 5 seconds">
 16		<cfset assert("loc.e eq loc.r")>
 17	</cffunction>
 18
 19	<cffunction name="test_with_seconds_below_10_seconds">
 20		<cfset loc.c = 10 - 1>
 21		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 22		<cfset debug("loc.controller.distanceOfTimeInWords(argumentcollection=loc.args)", false)>
 23		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 24		<cfset loc.r = "less than 10 seconds">
 25		<cfset assert("loc.e eq loc.r")>
 26	</cffunction>
 27
 28	<cffunction name="test_with_seconds_below_20_seconds">
 29		<cfset loc.c = 20 - 1>
 30		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 31		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 32		<cfset loc.r = "less than 20 seconds">
 33		<cfset assert("loc.e eq loc.r")>
 34	</cffunction>
 35
 36	<cffunction name="test_with_seconds_below_40_seconds">
 37		<cfset loc.c = 40 - 1>
 38		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 39		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 40		<cfset loc.r = "half a minute">
 41		<cfset assert("loc.e eq loc.r")>
 42	</cffunction>
 43
 44	<cffunction name="test_with_seconds_below_60_seconds">
 45		<cfset loc.c = 60 - 1>
 46		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 47		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 48		<cfset loc.r = "less than a minute">
 49		<cfset assert("loc.e eq loc.r")>
 50	</cffunction>
 51
 52	<cffunction name="test_with_seconds_above_60_seconds">
 53		<cfset loc.c = 60 + 50>
 54		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 55		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 56		<cfset loc.r = "1 minute">
 57		<cfset assert("loc.e eq loc.r")>
 58	</cffunction>
 59
 60	<cffunction name="test_without_seconds_below_60_seconds">
 61		<cfset loc.args.includeSeconds = false>
 62		<cfset loc.c = 60 - 1>
 63		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 64		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 65		<cfset loc.r = "less than a minute">
 66		<cfset assert("loc.e eq loc.r")>
 67	</cffunction>
 68
 69	<cffunction name="test_without_seconds_above_60_seconds">
 70		<cfset loc.args.includeSeconds = false>
 71		<cfset loc.c = 60 + 50>
 72		<cfset loc.args.toTime = dateadd('s', loc.c, loc.args.fromTime)>
 73		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 74		<cfset loc.r = "1 minute">
 75		<cfset assert("loc.e eq loc.r")>
 76	</cffunction>
 77
 78	<cffunction name="test_without_seconds_below_45_minutes">
 79		<cfset loc.args.includeSeconds = false>
 80		<cfset loc.c = 45 - 1>
 81		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
 82		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 83		<cfset loc.r = "#loc.c# minutes">
 84		<cfset assert("loc.e eq loc.r")>
 85	</cffunction>
 86
 87	<cffunction name="test_without_seconds_below_90_minutes">
 88		<cfset loc.args.includeSeconds = false>
 89		<cfset loc.c = 90 - 1>
 90		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
 91		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
 92		<cfset loc.r = "about 1 hour">
 93		<cfset assert("loc.e eq loc.r")>
 94	</cffunction>
 95
 96	<cffunction name="test_without_seconds_below_1440_minutes">
 97		<cfset loc.args.includeSeconds = false>
 98		<cfset loc.c = 1440 - 1>
 99		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
100		<cfset loc.c = Ceiling(loc.c/60)>
101		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
102		<cfset loc.r = "about #loc.c# hours">
103		<cfset assert("loc.e eq loc.r")>
104	</cffunction>
105
106	<cffunction name="test_without_seconds_below_2880_minutes">
107		<cfset loc.args.includeSeconds = false>
108		<cfset loc.c = 2880 - 1>
109		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
110		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
111		<cfset loc.r = "1 day">
112		<cfset assert("loc.e eq loc.r")>
113	</cffunction>
114
115	<cffunction name="test_without_seconds_below_43200_minutes">
116		<cfset loc.args.includeSeconds = false>
117		<cfset loc.c = 43200 - 1>
118		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
119		<cfset loc.c = Int(loc.c/1440)>
120		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
121		<cfset loc.r = "#loc.c# days">
122		<cfset assert("loc.e eq loc.r")>
123	</cffunction>
124
125	<cffunction name="test_without_seconds_below_86400_minutes">
126		<cfset loc.args.includeSeconds = false>
127		<cfset loc.c = 86400 - 1>
128		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
129		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
130		<cfset loc.r = "about 1 month">
131		<cfset assert("loc.e eq loc.r")>
132	</cffunction>
133
134	<cffunction name="test_without_seconds_below_525600_minutes">
135		<cfset loc.args.includeSeconds = false>
136		<cfset loc.c = 525600 - 1>
137		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
138		<cfset loc.c = Int(loc.c/43200)>
139		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
140		<cfset loc.r = "#loc.c# months">
141		<cfset assert("loc.e eq loc.r")>
142	</cffunction>
143
144	<cffunction name="test_without_seconds_below_657000_minutes">
145		<cfset loc.args.includeSeconds = false>
146		<cfset loc.c = 657000 - 1>
147		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
148		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
149		<cfset loc.r = "about 1 year">
150		<cfset assert("loc.e eq loc.r")>
151	</cffunction>
152
153	<cffunction name="test_without_seconds_below_919800_minutes">
154		<cfset loc.args.includeSeconds = false>
155		<cfset loc.c = 919800 - 1>
156		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
157		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
158		<cfset loc.r = "over 1 year">
159		<cfset assert("loc.e eq loc.r")>
160	</cffunction>
161
162	<cffunction name="test_without_seconds_below_1051200_minutes">
163		<cfset loc.args.includeSeconds = false>
164		<cfset loc.c = 1051200 - 1>
165		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
166		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
167		<cfset loc.r = "almost 2 years">
168		<cfset assert("loc.e eq loc.r")>
169	</cffunction>
170
171	<cffunction name="test_without_seconds_above_1051200_minutes">
172		<cfset loc.args.includeSeconds = false>
173		<cfset loc.c = 1051200>
174		<cfset loc.c = (loc.c * 3) + 786>
175		<cfset loc.args.toTime = dateadd('n', loc.c, loc.args.fromTime)>
176		<cfset loc.c = Int(loc.c/525600)>
177		<cfinvoke component="#loc.controller#" method="#loc.f#" argumentcollection="#loc.args#" returnvariable="loc.e">
178		<cfset loc.r = "over #loc.c# years">
179		<cfset assert("loc.e eq loc.r")>
180	</cffunction>
181
182</cfcomponent>