mirror of
				https://github.com/Jermolene/TiddlyWiki5
				synced 2025-10-30 23:23:02 +00:00 
			
		
		
		
	Some tests and style updates for #1229
@tobibeer I simplified the handling of matched strings a little.
This commit is contained in:
		| @@ -176,8 +176,7 @@ exports.slowInSlowOut = function(t) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| exports.formatDateString = function(date,template) { | exports.formatDateString = function(date,template) { | ||||||
| 	var match, | 	var result = "", | ||||||
| 		result="", |  | ||||||
| 		t = template, | 		t = template, | ||||||
| 		matches = [ | 		matches = [ | ||||||
| 			[/^0hh12/, function() { | 			[/^0hh12/, function() { | ||||||
| @@ -261,22 +260,19 @@ exports.formatDateString = function(date,template) { | |||||||
| 				return $tw.utils.pad(date.getFullYear() - 2000); | 				return $tw.utils.pad(date.getFullYear() - 2000); | ||||||
| 			}] | 			}] | ||||||
| 		]; | 		]; | ||||||
|  |  | ||||||
| 	while(t.length){ | 	while(t.length){ | ||||||
| 		match = ""; | 		var matchString = ""; | ||||||
| 		$tw.utils.each(matches, function(m) { | 		$tw.utils.each(matches, function(m) { | ||||||
| 			var r,l; | 			var r,l, | ||||||
| 			if(t.match(m[0])) { | 				match = m[0].exec(t); | ||||||
| 				match = m[1].call(); | 			if(match) { | ||||||
| 				r = m[0].toString(), | 				matchString = m[1].call(); | ||||||
| 				l = r.length - 3; | 				t = t.substr(match[0].length); | ||||||
| 				l = r.substr(2,1) == "[" ? l - 3 : l; |  | ||||||
| 				t = t.substr(l); |  | ||||||
| 				return false; | 				return false; | ||||||
| 			} | 			} | ||||||
| 		}); | 		}); | ||||||
| 		if(match) { | 		if(matchString) { | ||||||
| 			result += match; | 			result += matchString; | ||||||
| 		} else { | 		} else { | ||||||
| 			result += t.charAt(0); | 			result += t.charAt(0); | ||||||
| 			t = t.substr(1); | 			t = t.substr(1); | ||||||
|   | |||||||
| @@ -25,6 +25,15 @@ describe("Utility tests", function() { | |||||||
| 		expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]); | 		expect(psa(" [[Tidd\u00a0ler8]] two ")).toEqual(["Tidd\u00a0ler8","two"]); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
|  | 	it("should handle formatting a date string", function() { | ||||||
|  | 		var fds = $tw.utils.formatDateString, | ||||||
|  | 			d = new Date(2014,10,9,17,41,28,542); | ||||||
|  | 		expect(fds(d,"DDD DD MMM YYYY")).toBe("Sunday 9 November 2014"); | ||||||
|  | 		expect(fds(d,"ddd hh mm ssss")).toBe("Sun 17 41 2828"); | ||||||
|  | 		expect(fds(d,"MM0DD")).toBe("1109"); | ||||||
|  | 		expect(fds(d,"MM0\\D\\D")).toBe("110DD"); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
| 	it("should parse text references", function() { | 	it("should parse text references", function() { | ||||||
| 		var ptr = $tw.utils.parseTextReference; | 		var ptr = $tw.utils.parseTextReference; | ||||||
| 		expect(ptr("title")).toEqual( | 		expect(ptr("title")).toEqual( | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ The ViewWidget accepts a `template` attribute that allows the format of date val | |||||||
| |`DD` |Day of month | | |`DD` |Day of month | | ||||||
| |`0DD` |Adds a leading zero | | |`0DD` |Adds a leading zero | | ||||||
| |`DDth` |Adds a suffix | | |`DDth` |Adds a suffix | | ||||||
| |`WW` |~ISO-8601 week number of year | | |`WW` |ISO-8601 week number of year | | ||||||
| |`0WW` |Adds a leading zero | | |`0WW` |Adds a leading zero | | ||||||
| |`MMM` |Month in full (eg, "July") | | |`MMM` |Month in full (eg, "July") | | ||||||
| |`mmm` |Short month (eg, "Jul") | | |`mmm` |Short month (eg, "Jul") | | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jermolene
					Jermolene