-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Elements: Weather PR refactor (#1927)
- Loading branch information
1 parent
f92ad9a
commit aa92dde
Showing
6 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
Binary file added
BIN
+2.76 KB
modules/assets/template-thumbnails/forecast/elements/weather-date.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// --- Add global TOOLS for the CMS ---- | ||
window.formHelpers = require('./src/helpers/form-helpers.js'); | ||
window.transformer = require('./src/helpers/transformer.js'); | ||
window.DateFormatHelper = require('./src/helpers/date-format-helper.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const DateFormatHelper = function(options) { | ||
this.timezone = null; | ||
this.systemFormat = 'Y-m-d H:i:s'; | ||
|
||
this.convertPhpToMomentFormat = function(format) { | ||
if (String(format).length === 0) { | ||
return ''; | ||
} | ||
|
||
const replacements = { | ||
d: 'DD', | ||
D: 'ddd', | ||
j: 'D', | ||
l: 'dddd', | ||
N: 'E', | ||
S: 'o', | ||
w: 'e', | ||
z: 'DDD', | ||
W: 'W', | ||
F: 'MMMM', | ||
m: 'MM', | ||
M: 'MMM', | ||
n: 'M', | ||
t: '', // no equivalent | ||
L: '', // no equivalent | ||
o: 'YYYY', | ||
Y: 'YYYY', | ||
y: 'YY', | ||
a: 'a', | ||
A: 'A', | ||
B: '', // no equivalent | ||
g: 'h', | ||
G: 'H', | ||
h: 'hh', | ||
H: 'HH', | ||
i: 'mm', | ||
s: 'ss', | ||
u: 'SSS', | ||
e: 'zz', // deprecated since version 1.6.0 of moment.js | ||
I: '', // no equivalent | ||
O: '', // no equivalent | ||
P: '', // no equivalent | ||
T: '', // no equivalent | ||
Z: '', // no equivalent | ||
c: '', // no equivalent | ||
r: '', // no equivalent | ||
U: 'X', | ||
}; | ||
let convertedFormat = ''; | ||
|
||
String(format).split('').forEach(function(char) { | ||
if (Object.keys(replacements).indexOf(char) === -1) { | ||
convertedFormat += char; | ||
} else { | ||
convertedFormat += replacements[char]; | ||
} | ||
}); | ||
|
||
return convertedFormat; | ||
}; | ||
|
||
return this; | ||
}; | ||
|
||
module.exports = new DateFormatHelper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters