Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit a2d136e

Browse files
author
Dan Cryer
committed
Fixes for date JS issues in Safari
1 parent 60dab35 commit a2d136e

File tree

2 files changed

+85
-114
lines changed

2 files changed

+85
-114
lines changed

public/assets/js/build-plugins/time.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,21 @@ var timePlugin = ActiveBuild.UiPlugin.extend({
99
},
1010

1111
render: function() {
12-
var created = new Date(ActiveBuild.buildData.created);
12+
var created = '';
13+
var started = '';
14+
var finished = '';
15+
16+
if (ActiveBuild.buildData.created) {
17+
created = dateFormat(ActiveBuild.buildData.created);
18+
}
19+
20+
if (ActiveBuild.buildData.started) {
21+
started = dateFormat(ActiveBuild.buildData.started);
22+
}
23+
24+
if (ActiveBuild.buildData.finished) {
25+
finished = dateFormat(ActiveBuild.buildData.finished);
26+
}
1327

1428
return '<table class="table table-striped table-bordered">' +
1529
'<thead>' +
@@ -21,9 +35,9 @@ var timePlugin = ActiveBuild.UiPlugin.extend({
2135
'</thead>' +
2236
'<tbody>' +
2337
'<tr>' +
24-
'<td id="created">' + created.format('mmm d yyyy, H:MM') + '</td>' +
25-
'<td id="started">' + ActiveBuild.buildData.started + '</td>' +
26-
'<td id="finished">' + ActiveBuild.buildData.finished + '</td>' +
38+
'<td id="created">' + created + '</td>' +
39+
'<td id="started">' + started + '</td>' +
40+
'<td id="finished">' + finished + '</td>' +
2741
'</tr>' +
2842
'</tbody>' +
2943
'</table>';
@@ -32,20 +46,23 @@ var timePlugin = ActiveBuild.UiPlugin.extend({
3246
onUpdate: function(e) {
3347
var build = e.queryData;
3448

35-
var created = new Date(build.created);
36-
49+
var created = '';
3750
var started = '';
51+
var finished = '';
52+
53+
if (build.created) {
54+
created = dateFormat(build.created);
55+
}
56+
3857
if (build.started) {
39-
var started = new Date(build.started);
40-
started = started.format('mmm d yyyy, H:MM');
58+
started = dateFormat(build.started);
4159
}
4260

43-
var finished = '';
4461
if (build.finished) {
45-
var finished = new Date(build.finished);
46-
finished = finished.format('mmm d yyyy, H:MM');
62+
finished = dateFormat(build.finished);
4763
}
48-
$('#created').text(created.format('mmm d yyyy, H:MM'));
64+
65+
$('#created').text(created);
4966
$('#started').text(started);
5067
$('#finished').text(finished);
5168
}

public/assets/js/phpci.js

Lines changed: 56 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -407,114 +407,68 @@ function setupProjectForm()
407407
});
408408
}
409409

410-
var dateFormat = function () {
411-
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
412-
timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
413-
timezoneClip = /[^-+\dA-Z]/g,
414-
pad = function (val, len) {
415-
val = String(val);
416-
len = len || 2;
417-
while (val.length < len) val = "0" + val;
418-
return val;
419-
};
420410

421-
// Regexes and supporting functions are cached through closure
422-
return function (date, mask, utc) {
423-
var dF = dateFormat;
424411

425-
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
426-
if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
427-
mask = date;
428-
date = undefined;
429-
}
412+
function dateFormat(date)
413+
{
414+
if (typeof date == 'string') {
415+
date = new Date(date);
416+
}
417+
418+
var rtn = '';
430419

431-
// Passing date through Date applies Date.parse, if necessary
432-
date = date ? new Date(date) : new Date;
433-
if (isNaN(date)) throw SyntaxError("invalid date");
420+
switch (date.getMonth()) {
421+
case 0:
422+
rtn = 'Jan ';
423+
break;
434424

435-
mask = String(dF.masks[mask] || mask || dF.masks["default"]);
425+
case 1:
426+
rtn = 'Feb ';
427+
break;
436428

437-
// Allow setting the utc argument via the mask
438-
if (mask.slice(0, 4) == "UTC:") {
439-
mask = mask.slice(4);
440-
utc = true;
441-
}
429+
case 2:
430+
rtn = 'Mar ';
431+
break;
442432

443-
var _ = utc ? "getUTC" : "get",
444-
d = date[_ + "Date"](),
445-
D = date[_ + "Day"](),
446-
m = date[_ + "Month"](),
447-
y = date[_ + "FullYear"](),
448-
H = date[_ + "Hours"](),
449-
M = date[_ + "Minutes"](),
450-
s = date[_ + "Seconds"](),
451-
L = date[_ + "Milliseconds"](),
452-
o = utc ? 0 : date.getTimezoneOffset(),
453-
flags = {
454-
d: d,
455-
dd: pad(d),
456-
ddd: dF.i18n.dayNames[D],
457-
dddd: dF.i18n.dayNames[D + 7],
458-
m: m + 1,
459-
mm: pad(m + 1),
460-
mmm: dF.i18n.monthNames[m],
461-
mmmm: dF.i18n.monthNames[m + 12],
462-
yy: String(y).slice(2),
463-
yyyy: y,
464-
h: H % 12 || 12,
465-
hh: pad(H % 12 || 12),
466-
H: H,
467-
HH: pad(H),
468-
M: M,
469-
MM: pad(M),
470-
s: s,
471-
ss: pad(s),
472-
l: pad(L, 3),
473-
L: pad(L > 99 ? Math.round(L / 10) : L),
474-
t: H < 12 ? "a" : "p",
475-
tt: H < 12 ? "am" : "pm",
476-
T: H < 12 ? "A" : "P",
477-
TT: H < 12 ? "AM" : "PM",
478-
Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
479-
o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
480-
S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
481-
};
433+
case 3:
434+
rtn = 'Apr ';
435+
break;
482436

483-
return mask.replace(token, function ($0) {
484-
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
485-
});
486-
};
487-
}();
488-
489-
// Some common format strings
490-
dateFormat.masks = {
491-
"default": "ddd mmm dd yyyy HH:MM:ss",
492-
shortDate: "m/d/yy",
493-
mediumDate: "mmm d, yyyy",
494-
longDate: "mmmm d, yyyy",
495-
fullDate: "dddd, mmmm d, yyyy",
496-
shortTime: "h:MM TT",
497-
mediumTime: "h:MM:ss TT",
498-
longTime: "h:MM:ss TT Z",
499-
isoDate: "yyyy-mm-dd",
500-
isoTime: "HH:MM:ss",
501-
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
502-
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
503-
};
437+
case 4:
438+
rtn = 'May ';
439+
break;
504440

505-
// Internationalization strings
506-
dateFormat.i18n = {
507-
dayNames: [
508-
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
509-
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
510-
],
511-
monthNames: [
512-
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
513-
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
514-
]
515-
};
441+
case 5:
442+
rtn = 'Jun ';
443+
break;
444+
445+
case 6:
446+
rtn = 'Jul ';
447+
break;
448+
449+
case 7:
450+
rtn = 'Aug ';
451+
break;
452+
453+
case 8:
454+
rtn = 'Sep ';
455+
break;
456+
457+
case 9:
458+
rtn = 'Oct ';
459+
break;
460+
461+
case 10:
462+
rtn = 'Nov ';
463+
break;
464+
465+
case 11:
466+
rtn = 'Dec ';
467+
break;
468+
}
469+
470+
rtn += date.getDate() + ' ' + date.getFullYear();
471+
rtn += ' ' + date.getHours() + ':' + date.getMinutes();
516472

517-
// For convenience...
518-
Date.prototype.format = function (mask, utc) {
519-
return dateFormat(this, mask, utc);
520-
};
473+
return rtn;
474+
}

0 commit comments

Comments
 (0)