Skip to content

Commit

Permalink
cdate Updated to 0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
FSolM committed Feb 24, 2020
1 parent 65ec521 commit eff8bb5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 81 deletions.
14 changes: 5 additions & 9 deletions lib/cdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ export default (format = 'mm/dd/yy', options = { compact: true, fullDate: false
}
format.toLowerCase();
const d = new Date().toString().split(' ');
try {
let date = formatter(d, format, options.compact);
if (options.fullDate) {
return `${options.compact ? d[0] : getDays(d[0])}, ${date}`;
} else {
return date;
}
} catch {
return undefined;
let date = formatter(d, format, options);
if (options.fullDate) {
return `${options.compact ? d[0] : getDays(d[0], true)}, ${date}`;
} else {
return date;
}
}
48 changes: 20 additions & 28 deletions lib/helpers/days.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@

const longDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];

export default (monthString, style = 'short') => {
style = style.toLowerCase();
if (style === 'short') {
return monthString;
} else if (stryle === 'long') {
switch (monthString) {
case 'Mon':
return longDays[0];
case 'Tue':
return longDays[1];
case 'Wed':
return longDays[2];
case 'Thu':
return longDays[3];
case 'Fri':
return longDays[4];
case 'Sat':
return longDays[5];
case 'Sun':
return longDays[6];
default:
console.error("Couldn't convert Days to string");
return new Error();
};
} else {
console.error('The style you specified is unknown');
return new Error()
}
export default (monthString) => {
switch (monthString) {
case 'Mon':
return longDays[0];
case 'Tue':
return longDays[1];
case 'Wed':
return longDays[2];
case 'Thu':
return longDays[3];
case 'Fri':
return longDays[4];
case 'Sat':
return longDays[5];
case 'Sun':
return longDays[6];
default:
console.error("Couldn't convert Days to string");
return undefined;
};
};
10 changes: 5 additions & 5 deletions lib/helpers/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import getMonths from './months';
export default (d, format, compact) => {
switch (format) {
case 'mm/dd/yy':
return `${compact ? d[1] : getMonths(d[1])} ${d[2]} ${compact ? d[3].substring(0, 2) : d[3]}`;
return `${compact ? d[1] : getMonths(d[1])} ${d[2]} ${d[3]}`;
case 'dd/mm/yy':
return `${d[2]} ${compact ? d[1] : getMonths(d[1])} ${compact ? d[3].substring(0, 2) : d[3]}`;
return `${d[2]} ${compact ? d[1] : getMonths(d[1])} ${d[3]}`;
case 'yy/mm/dd':
return `${compact ? d[3].substring(0, 2) : d[3]} ${d[2]} ${compact ? d[1] : getMonths(d[1])}`;
return `${d[3]} ${d[2]} ${compact ? d[1] : getMonths(d[1])}`;
case 'yy/dd/mm':
return `${compact ? d[3].substring(0, 2) : d[3]} ${compact ? d[1] : getMonths(d[1])} ${d[2]}`;
return `${d[3]} ${compact ? d[1] : getMonths(d[1])} ${d[2]}`;
default:
console.error('Seems like the date format is wrong');
return new Error();
return undefined;
}
}
68 changes: 30 additions & 38 deletions lib/helpers/months.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,34 @@

const longMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

export default (monthString, style = 'short') => {
style = style.toLowerCase();
if (style === 'short') {
return monthString;
} else if (style === 'long') {
switch (monthString) {
case 'Jan':
return longMonths[0];
case 'Feb':
return longMonths[1];
case 'Mar':
return longMonths[2];
case 'Apr':
return longMonths[3];
case 'May':
return longMonths[4];
case 'Jun':
return longMonths[5];
case 'Jul':
return longMonths[6];
case 'Agu':
return longMonths[7];
case 'Sep':
return longMonths[8];
case 'Oct':
return longMonths[9];
case 'Nov':
return longMonths[10];
case 'Dic':
return longMonths[11];
default:
console.error("Couldn't convert Months to string");
return new Error();
};
} else {
console.error('The style you specified is unknown');
return new Error()
}
export default (monthString) => {
switch (monthString) {
case 'Jan':
return longMonths[0];
case 'Feb':
return longMonths[1];
case 'Mar':
return longMonths[2];
case 'Apr':
return longMonths[3];
case 'May':
return longMonths[4];
case 'Jun':
return longMonths[5];
case 'Jul':
return longMonths[6];
case 'Agu':
return longMonths[7];
case 'Sep':
return longMonths[8];
case 'Oct':
return longMonths[9];
case 'Nov':
return longMonths[10];
case 'Dic':
return longMonths[11];
default:
console.error("Couldn't convert Months to string");
return undefined;
};
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "cdate-formatting",
"version": "0.5.0",
"version": "0.5.5",
"description": "A simple Node package library for quick JS Date formatting",
"main": "index.js",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/FSolM/cdate-formatting.git"
Expand Down

0 comments on commit eff8bb5

Please sign in to comment.