source: EDIS/trunk/java/tracking-ui-core/src/main/flex/gov/va/med/edp/util/Vista.as@ 1227

Last change on this file since 1227 was 1227, checked in by George Lilly, 13 years ago

initial load of EDIS 1.0

File size: 2.4 KB
Line 
1/* Vista.as */
2
3package gov.va.med.edp.util
4{
5 import mx.collections.ICollectionView;
6 import mx.formatters.DateFormatter;
7
8 public class Vista
9 {
10 private static const DT_FORMAT: String = "D MMM YY J:NN";
11
12 /*
13 Searches a collection for the index of the item that matches that data value
14 */
15 public static function locateIndex(collection: ICollectionView,
16 value: Object, property: String = "data"): int
17 {
18 for (var i:int; i < collection.length; i++) {
19 var item:Object = collection[i];
20 if (item.hasOwnProperty(property) && (item[property] == value)) return i;
21 }
22 return -1;
23 }
24
25 /*
26 Returns the numeric identifier for an object at an index in a collection
27 */
28 public static function getIDFieldAtIndex(collection: ICollectionView,
29 index: int, property: String = "data"): Number
30 {
31 if (index < 0) return NaN;
32 if (index < collection.length) {
33 var item:Object = collection[index];
34 if (item.hasOwnProperty(property)) return item[property];
35 }
36 return NaN;
37 }
38
39 public static function FMtoDate(fmDT: String): Date
40 {
41 if (fmDT.length < 7) {
42 return null;
43 }
44
45 var x:String = fmDT + "00000";
46 var y:int = int(x.substr(0,3)) + 1700;
47 var m:int = int(x.substr(3,2)) - 1;
48 var d:int = int(x.substr(5,2));
49 var h:int = int(x.substr(8,2));
50 var n:int = int(x.substr(10,2));
51 return new Date(y,m,d,h,n);
52 }
53
54 public static function DatetoFM(aDate: Date): String
55 {
56 if (aDate == null) return "";
57
58 var y:int = (aDate.fullYear - 1700) * 10000;
59 var m:int = (aDate.month + 1) * 100;
60 var d:int = aDate.date;
61 var h:String = "00" + String(aDate.hours);
62 var n:String = "00" + String(aDate.minutes);
63
64 if ((y+m+d) == 0) return "";
65
66 if ((aDate.hours + aDate.minutes) > 0) {
67 return String(y+m+d) + "." + h.substr(-2,2) + n.substr(-2,2);
68 } else {
69 return String(y+m+d);
70 }
71 }
72
73 public static function formattedDate(aDate: Date, formatString:String=null): String
74 {
75 if (aDate == null) {
76 return "";
77 }
78
79 var formatter:DateFormatter = new DateFormatter();
80 if (formatString != null){
81 formatter.formatString = formatString;
82 } else {
83 formatter.formatString = DT_FORMAT;
84 }
85
86 return formatter.format(aDate);
87 }
88
89 public static function getBooleanValueForString(str: String): Boolean
90 {
91 if (str == "true") {
92 return true;
93 }
94 return false;
95 }
96 }
97}
Note: See TracBrowser for help on using the repository browser.