CPE_learningsite
This repository has no backups
This repository's network speed is throttled to 100KB/sec
Upgrade your account to fix these warnings, or use backups.vc for automated backups
4cd176a439ea516368a5d8827cdf8726027259a6
CPE_learningsite / CPEFlex / EngagementPod / src / models / TimeSpan.as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
package models { /** * Represents an interval of time */ public class TimeSpan { private var _totalMilliseconds : Number; public function TimeSpan(milliseconds : Number) { _totalMilliseconds = Math.floor(milliseconds); } /** * Gets the number of whole days * * @example In a TimeSpan created from TimeSpan.fromHours(25), * totalHours will be 1.04, but hours will be 1 * @return A number representing the number of whole days in the TimeSpan */ public function get days() : int { return int(_totalMilliseconds / MILLISECONDS_IN_DAY); } /** * Gets the number of whole hours (excluding entire days) * * @example In a TimeSpan created from TimeSpan.fromMinutes(1500), * totalHours will be 25, but hours will be 1 * @return A number representing the number of whole hours in the TimeSpan */ public function get hours() : int { return int(_totalMilliseconds / MILLISECONDS_IN_HOUR) % 24; } /** * Gets the number of whole minutes (excluding entire hours) * * @example In a TimeSpan created from TimeSpan.fromMilliseconds(65500), * totalSeconds will be 65.5, but seconds will be 5 * @return A number representing the number of whole minutes in the TimeSpan */ public function get minutes() : int { return int(_totalMilliseconds / MILLISECONDS_IN_MINUTE) % 60; } /** * Gets the number of whole seconds (excluding entire minutes) * * @example In a TimeSpan created from TimeSpan.fromMilliseconds(65500), * totalSeconds will be 65.5, but seconds will be 5 * @return A number representing the number of whole seconds in the TimeSpan */ public function get seconds() : int { return int(_totalMilliseconds / MILLISECONDS_IN_SECOND) % 60; } /** * Gets the number of whole milliseconds (excluding entire seconds) * * @example In a TimeSpan created from TimeSpan.fromMilliseconds(2123), * totalMilliseconds will be 2001, but milliseconds will be 123 * @return A number representing the number of whole milliseconds in the TimeSpan */ public function get milliseconds() : int { return int(_totalMilliseconds) % 1000; } /** * Gets the total number of days. * * @example In a TimeSpan created from TimeSpan.fromHours(25), * totalHours will be 1.04, but hours will be 1 * @return A number representing the total number of days in the TimeSpan */ public function get totalDays() : Number { return _totalMilliseconds / MILLISECONDS_IN_DAY; } /** * Gets the total number of hours. * * @example In a TimeSpan created from TimeSpan.fromMinutes(1500), * totalHours will be 25, but hours will be 1 * @return A number representing the total number of hours in the TimeSpan */ public function get totalHours() : Number { return _totalMilliseconds / MILLISECONDS_IN_HOUR; } /** * Gets the total number of minutes. * * @example In a TimeSpan created from TimeSpan.fromMilliseconds(65500), * totalSeconds will be 65.5, but seconds will be 5 * @return A number representing the total number of minutes in the TimeSpan */ public function get totalMinutes() : Number { return _totalMilliseconds / MILLISECONDS_IN_MINUTE; } /** * Gets the total number of seconds. * * @example In a TimeSpan created from TimeSpan.fromMilliseconds(65500), * totalSeconds will be 65.5, but seconds will be 5 * @return A number representing the total number of seconds in the TimeSpan */ public function get totalSeconds() : Number { return _totalMilliseconds / MILLISECONDS_IN_SECOND; } /** * Gets the total number of milliseconds. * * @example In a TimeSpan created from TimeSpan.fromMilliseconds(2123), * totalMilliseconds will be 2001, but milliseconds will be 123 * @return A number representing the total number of milliseconds in the TimeSpan */ public function get totalMilliseconds() : Number { return _totalMilliseconds; } /** * Adds the timespan represented by this instance to the date provided and returns a new date object. * @param date The date to add the timespan to * @return A new Date with the offseted time */ public function add(date : Date) : Date { var ret : Date = new Date(date.time); ret.milliseconds += totalMilliseconds; return ret; } /** * Creates a TimeSpan from the different between two dates * * Note that start can be after end, but it will result in negative values. * * @param start The start date of the timespan * @param end The end date of the timespan * @return A TimeSpan that represents the difference between the dates * */ public static function fromDates(start : Date, end : Date) : TimeSpan { return new TimeSpan(end.time - start.time); } /** * Creates a TimeSpan from the specified number of milliseconds * @param milliseconds The number of milliseconds in the timespan * @return A TimeSpan that represents the specified value */ public static function fromMilliseconds(milliseconds : Number) : TimeSpan { return new TimeSpan(milliseconds); } /** * Creates a TimeSpan from the specified number of seconds * @param seconds The number of seconds in the timespan * @return A TimeSpan that represents the specified value */ public static function fromSeconds(seconds : Number) : TimeSpan { return new TimeSpan(seconds * MILLISECONDS_IN_SECOND); } /** * Creates a TimeSpan from the specified number of minutes * @param minutes The number of minutes in the timespan * @return A TimeSpan that represents the specified value */ public static function fromMinutes(minutes : Number) : TimeSpan { return new TimeSpan(minutes * MILLISECONDS_IN_MINUTE); } /** * Creates a TimeSpan from the specified number of hours * @param hours The number of hours in the timespan * @return A TimeSpan that represents the specified value */ public static function fromHours(hours : Number) : TimeSpan { return new TimeSpan(hours * MILLISECONDS_IN_HOUR); } /** * Creates a TimeSpan from the specified number of days * @param days The number of days in the timespan * @return A TimeSpan that represents the specified value */ public static function fromDays(days : Number) : TimeSpan { return new TimeSpan(days * MILLISECONDS_IN_DAY); } /** * The number of milliseconds in one day */ public static const MILLISECONDS_IN_DAY : Number = 86400000; /** * The number of milliseconds in one hour */ public static const MILLISECONDS_IN_HOUR : Number = 3600000; /** * The number of milliseconds in one minute */ public static const MILLISECONDS_IN_MINUTE : Number = 60000; /** * The number of milliseconds in one second */ public static const MILLISECONDS_IN_SECOND : Number = 1000; } } |
Commits for CPE_learningsiteCPEFlex/EngagementPod/src/models/TimeSpan.as
Revision | Author | Commited | Message |
---|---|---|---|
4cd176 ... | v.shishlov | Fri 27 Aug, 2021 14:33:17 +0000 | initial commit |