PageRenderTime 303ms CodeModel.GetById 120ms app.highlight 2ms RepoModel.GetById 179ms app.codeStats 0ms

/wheels/tests/view/dates/timeAgoInWords.cfc

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