mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
Add IIFE.
This commit is contained in:
parent
712cba57b8
commit
c8d8e566f8
@ -1,32 +1,37 @@
|
||||
/**
|
||||
The HackMyResume date representation.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module fluent-date.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module core/fluent-date
|
||||
*/
|
||||
|
||||
var moment = require('moment');
|
||||
(function(){
|
||||
|
||||
/**
|
||||
Create a FluentDate from a string or Moment date object. There are a few date
|
||||
formats to be aware of here.
|
||||
1. The words "Present" and "Now", referring to the current date
|
||||
2. The default "YYYY-MM-DD" format used in JSON Resume ("2015-02-10")
|
||||
3. Year-and-month only ("2015-04")
|
||||
4. Year-only "YYYY" ("2015")
|
||||
5. The friendly HackMyResume "mmm YYYY" format ("Mar 2015" or "Dec 2008")
|
||||
6. Empty dates ("", " ")
|
||||
7. Any other date format that Moment.js can parse from
|
||||
Note: Moment can transparently parse all or most of these, without requiring us
|
||||
to specify a date format...but for maximum parsing safety and to avoid Moment
|
||||
deprecation warnings, it's recommended to either a) explicitly specify the date
|
||||
format or b) use an ISO format. For clarity, we handle these cases explicitly.
|
||||
@class FluentDate
|
||||
*/
|
||||
function FluentDate( dt ) {
|
||||
var moment = require('moment');
|
||||
|
||||
/**
|
||||
Create a FluentDate from a string or Moment date object. There are a few date
|
||||
formats to be aware of here.
|
||||
1. The words "Present" and "Now", referring to the current date
|
||||
2. The default "YYYY-MM-DD" format used in JSON Resume ("2015-02-10")
|
||||
3. Year-and-month only ("2015-04")
|
||||
4. Year-only "YYYY" ("2015")
|
||||
5. The friendly HackMyResume "mmm YYYY" format ("Mar 2015" or "Dec 2008")
|
||||
6. Empty dates ("", " ")
|
||||
7. Any other date format that Moment.js can parse from
|
||||
Note: Moment can transparently parse all or most of these, without requiring us
|
||||
to specify a date format...but for maximum parsing safety and to avoid Moment
|
||||
deprecation warnings, it's recommended to either a) explicitly specify the date
|
||||
format or b) use an ISO format. For clarity, we handle these cases explicitly.
|
||||
@class FluentDate
|
||||
*/
|
||||
function FluentDate( dt ) {
|
||||
this.rep = this.fmt( dt );
|
||||
}
|
||||
}
|
||||
|
||||
FluentDate/*.prototype*/.fmt = function( dt, throws ) {
|
||||
|
||||
throws = (throws === undefined || throws === null) || throws;
|
||||
|
||||
FluentDate/*.prototype*/.fmt = function( dt ) {
|
||||
if( (typeof dt === 'string' || dt instanceof String) ) {
|
||||
dt = dt.toLowerCase().trim();
|
||||
if( /^(present|now|current)$/.test(dt) ) { // "Present", "Now"
|
||||
@ -63,7 +68,9 @@ FluentDate/*.prototype*/.fmt = function( dt ) {
|
||||
var mt = moment( dt );
|
||||
if(mt.isValid())
|
||||
return mt;
|
||||
if( throws )
|
||||
throw 'Invalid date format encountered.';
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -72,13 +79,17 @@ FluentDate/*.prototype*/.fmt = function( dt ) {
|
||||
}
|
||||
else if( dt.isValid && dt.isValid() )
|
||||
return dt;
|
||||
if( throws )
|
||||
throw 'Unknown date object encountered.';
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var months = {}, abbr = {};
|
||||
moment.months().forEach(function(m,idx){months[m.toLowerCase()]=idx+1;});
|
||||
moment.monthsShort().forEach(function(m,idx){abbr[m.toLowerCase()]=idx+1;});
|
||||
abbr.sept = 9;
|
||||
var months = {}, abbr = {};
|
||||
moment.months().forEach(function(m,idx){months[m.toLowerCase()]=idx+1;});
|
||||
moment.monthsShort().forEach(function(m,idx){abbr[m.toLowerCase()]=idx+1;});
|
||||
abbr.sept = 9;
|
||||
|
||||
module.exports = FluentDate;
|
||||
module.exports = FluentDate;
|
||||
|
||||
}());
|
||||
|
Loading…
Reference in New Issue
Block a user