-
-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow different date formatting like YYYY/MM/DD with Moment.js library. #31
base: master
Are you sure you want to change the base?
Changes from 4 commits
b4152ee
4d33ad6
e23567c
5e9adf4
1c97477
f873ebd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"customStylesheetURL": null, | ||
"yearLength": 120, | ||
"hideAge": false | ||
"hideAge": false, | ||
"dateFormats": ["YYYY", "MM/YYYY", "DD/MM/YYYY"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,7 @@ <h1 id="title">Life</h1> | |
<a href="https://github.com/cheeaun/life">Fork me</a> | ||
</header> | ||
<div id="life"></div> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.min.js"></script> | ||
<script> | ||
(function(){ | ||
var life = { | ||
|
@@ -177,22 +178,16 @@ <h1 id="title">Life</h1> | |
var data = {}; | ||
if (/^\~\d+$/.test(time)){ // ~YYYY | ||
data = { | ||
startYear: parseInt(time.slice(1), 10), | ||
startYear: moment(time.slice(1), "YYYY", true).year(), | ||
estimate: true | ||
}; | ||
} else if (/^\d+$/.test(time)){ // YYYY | ||
data[point + 'Year'] = parseInt(time, 10); | ||
} else if (/^\d+\/\d+$/.test(time)){ // MM/YYYY | ||
var t = time.split('/'); | ||
data[point + 'Month'] = parseInt(t[0], 10); | ||
data[point + 'Year'] = parseInt(t[1], 10); | ||
} else if (/^\d+\/\d+\/\d+$/.test(time)){ // DD/MM/YYYY | ||
var t = time.split('/'); | ||
data[point + 'Date'] = parseInt(t[0], 10); | ||
data[point + 'Month'] = parseInt(t[1], 10); | ||
data[point + 'Year'] = parseInt(t[2], 10); | ||
} else if(moment(time, life.config.dateFormats, true).isValid()){ | ||
var t = moment(time, life.config.dateFormats); | ||
data[point + 'Date'] = t.day(); | ||
data[point + 'Month'] = t.month(); | ||
data[point + 'Year'] = t.year(); | ||
} else if (/\d\-/.test(time)){ // TIME-TIME | ||
var splitTime = time.split('-'); | ||
var splitTime = time.split('-'); //bug We cannot use 2013-12-04 format! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could introduce another option for a custom separator but let's leave it like this first :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes definitely, we will need to use a different separator. |
||
var startTime = life.parseTime(splitTime[0]); | ||
var endTime = life.parseTime(splitTime[1], 'end'); | ||
for (var k in startTime) { data[k] = startTime[k] } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes please :)