climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject [02/50] git commit: Add ISODateToMiddleEndian filter
Date Mon, 21 Jul 2014 13:24:38 GMT
Add ISODateToMiddleEndian filter


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/8f13d2b9
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/8f13d2b9
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/8f13d2b9

Branch: refs/heads/master
Commit: 8f13d2b9177367e6a9cc56e6f77e6d3f0f4214b3
Parents: b39b3dd
Author: Michael Joyce <joyce@apache.org>
Authored: Wed Jul 16 10:22:11 2014 -0700
Committer: Michael Joyce <joyce@apache.org>
Committed: Wed Jul 16 10:22:11 2014 -0700

----------------------------------------------------------------------
 ocw-ui/frontend-new/app/index.html              |  1 +
 .../scripts/filters/isodatetomiddleendian.js    | 36 ++++++++++++++++++++
 .../test/spec/filters/isodatetomiddleendian.js  | 19 +++++++++++
 3 files changed, 56 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/8f13d2b9/ocw-ui/frontend-new/app/index.html
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend-new/app/index.html b/ocw-ui/frontend-new/app/index.html
index 2b07b4d..5ca9aad 100644
--- a/ocw-ui/frontend-new/app/index.html
+++ b/ocw-ui/frontend-new/app/index.html
@@ -104,6 +104,7 @@
     <script src="scripts/directives/predictivefilebrowserinput.js"></script>
     <script src="scripts/directives/previewmap.js"></script>
     <script src="scripts/directives/timeline.js"></script>
+    <script src="scripts/filters/isodatetomiddleendian.js"></script>
     <!-- endbuild -->
   </body>
 </html>

http://git-wip-us.apache.org/repos/asf/climate/blob/8f13d2b9/ocw-ui/frontend-new/app/scripts/filters/isodatetomiddleendian.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend-new/app/scripts/filters/isodatetomiddleendian.js b/ocw-ui/frontend-new/app/scripts/filters/isodatetomiddleendian.js
new file mode 100644
index 0000000..fce091c
--- /dev/null
+++ b/ocw-ui/frontend-new/app/scripts/filters/isodatetomiddleendian.js
@@ -0,0 +1,36 @@
+'use strict';
+
+/**
+ * @ngdoc filter
+ * @name ocwUiApp.filter:ISODateToMiddleEndian
+ * @function
+ * @description
+ * # ISODateToMiddleEndian
+ * Filter in the ocwUiApp.
+ */
+angular.module('ocwUiApp')
+.filter('ISODateToMiddleEndian', function() {
+	return function(input) {
+		var original = input;
+
+		// Strip whitespace from the start and end of the string
+		input = input.replace(/(^\s+|\s+$)/g, '');
+
+		// ISO Standard says time is separated from Date with a 'T'. Our timestamps
+		// slightly modify that and use a space. We'll check for both here and prefer
+		// to split on a 'T' if it's available.
+		if (input.indexOf('T') != -1 || input.indexOf(' ') != -1) {
+			input = (input.indexOf('T') != -1) ? input.split('T')[0] : input.split(' ')[0];
+		} 
+		
+		// The components of the date should be split with hyphens. If we can't find them
+		// then the string is poorly formed.
+		if (input.indexOf('-') == -1 || input.split('-').length - 1 != 2) {
+			return original;
+		}
+
+		// At this point the date is probably valid and we should try to convert it!
+		var components = input.split('-');
+		return (components[1] + "/" + components[2] + "/" + components[0]);
+	};
+});

http://git-wip-us.apache.org/repos/asf/climate/blob/8f13d2b9/ocw-ui/frontend-new/test/spec/filters/isodatetomiddleendian.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend-new/test/spec/filters/isodatetomiddleendian.js b/ocw-ui/frontend-new/test/spec/filters/isodatetomiddleendian.js
new file mode 100644
index 0000000..22d30a2
--- /dev/null
+++ b/ocw-ui/frontend-new/test/spec/filters/isodatetomiddleendian.js
@@ -0,0 +1,19 @@
+'use strict';
+
+describe('Filter: ISODateToMiddleEndian', function () {
+
+  // load the filter's module
+  beforeEach(module('ocwUiApp'));
+
+  // initialize a new instance of the filter before each test
+  var ISODateToMiddleEndian;
+  beforeEach(inject(function ($filter) {
+    ISODateToMiddleEndian = $filter('ISODateToMiddleEndian');
+  }));
+
+  it('should return the input prefixed with "ISODateToMiddleEndian filter:"', function ()
{
+    var text = 'angularjs';
+    expect(ISODateToMiddleEndian(text)).toBe('ISODateToMiddleEndian filter: ' + text);
+  });
+
+});


Mime
View raw message