-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
with duration computed from start-end-date and dates sortable probably fixes #43 Signed-off-by: Torbjörn Klatt <[email protected]>
- Loading branch information
1 parent
0282abd
commit 40fa7d3
Showing
7 changed files
with
187 additions
and
12 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* This plug-in for DataTables represents the ultimate option in extensibility | ||
* for sorting date / time strings correctly. It uses | ||
* [Moment.js](http://momentjs.com) to create automatic type detection and | ||
* sorting plug-ins for DataTables based on a given format. This way, DataTables | ||
* will automatically detect your temporal information and sort it correctly. | ||
* | ||
* For usage instructions, please see the DataTables blog | ||
* post that [introduces it](//datatables.net/blog/2014-12-18). | ||
* | ||
* @name Ultimate Date / Time sorting | ||
* @summary Sort date and time in any format using Moment.js | ||
* @author [Allan Jardine](//datatables.net) | ||
* @depends DataTables 1.10+, Moment.js 1.7+ | ||
* | ||
* @example | ||
* $.fn.dataTable.moment( 'HH:mm MMM D, YY' ); | ||
* $.fn.dataTable.moment( 'dddd, MMMM Do, YYYY' ); | ||
* | ||
* $('#example').DataTable(); | ||
*/ | ||
|
||
(function (factory) { | ||
if (typeof define === "function" && define.amd) { | ||
define(["jquery", "moment", "datatables"], factory); | ||
} else { | ||
factory(jQuery, moment); | ||
} | ||
}(function ($, moment) { | ||
|
||
$.fn.dataTable.moment = function ( format, locale ) { | ||
var types = $.fn.dataTable.ext.type; | ||
|
||
// Add type detection | ||
types.detect.unshift( function ( d ) { | ||
// Strip HTML tags if possible | ||
if ( d && d.replace ) { | ||
d = d.replace(/<.*?>/g, ''); | ||
} | ||
|
||
// Null and empty values are acceptable | ||
if ( d === '' || d === null ) { | ||
return 'moment-'+format; | ||
} | ||
|
||
return moment( d, format, locale, true ).isValid() ? | ||
'moment-'+format : | ||
null; | ||
} ); | ||
|
||
// Add sorting method - use an integer for the sorting | ||
types.order[ 'moment-'+format+'-pre' ] = function ( d ) { | ||
return d === '' || d === null ? | ||
-Infinity : | ||
parseInt( moment( d.replace ? d.replace(/<.*?>/g, '') : d, format, locale, true ).format( 'x' ), 10 ); | ||
}; | ||
}; | ||
|
||
})); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,4 +1,19 @@ | ||
- from: haensel_d | ||
to: balaji_p | ||
start: 2015-02-04 | ||
end: 2015-02-15 | ||
|
||
- from: haensel_d | ||
to: balaji_p | ||
start: 2016-02-04 | ||
end: 2016-02-14 | ||
end: 2016-02-15 | ||
|
||
- from: haensel_d | ||
to: balaji_p | ||
start: 2015-02-04 | ||
end: 2016-02-15 | ||
|
||
- from: haensel_d | ||
to: balaji_p | ||
start: 2015-12-04 | ||
end: 2016-01-15 |
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,5 +1,2 @@ | ||
<!-- Latest compiled and minified JavaScript --> | ||
{% js vendor/bootstrap.min.js %} | ||
{% js vendor/jquery.dataTables.min.js %} | ||
{% js vendor/dataTables.bootstrap.min.js %} | ||
{% js custom %} |
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,82 @@ | ||
module Jekyll | ||
module Tags | ||
class DurationTagError < StandardError | ||
def initialize(msg) | ||
super | ||
end | ||
end | ||
|
||
class DurationPMsTagError < DurationTagError | ||
def initialize(msg) | ||
super(msg) | ||
end | ||
end | ||
|
||
class DurationHumanizedTagError < DurationTagError | ||
def initialize(msg) | ||
super(msg) | ||
end | ||
end | ||
|
||
class DurationTag < Liquid::Tag | ||
SECONDS_PER_DAY = 86400 | ||
|
||
def initialize(tag_name, markup, tokens) | ||
super | ||
@markup = markup.strip | ||
end | ||
|
||
def days_from_seconds(context) | ||
seconds = Float(Liquid::Template.parse(@markup).render(context)) | ||
|
||
if seconds < 0 | ||
raise DurationTagError.new "Invalid duration. Must be at least one second: #{seconds}" | ||
end | ||
|
||
(seconds / 86400) + 1 | ||
end | ||
end | ||
|
||
class DurationPMsTag < DurationTag | ||
def render(context) | ||
days = days_from_seconds(context) | ||
"#{(days / 30.0).round(2)} PM" | ||
end | ||
end | ||
|
||
class DurationHumanizedTag < DurationTag | ||
DAYS_PER_MONTHS = 30 | ||
|
||
def days_to_s(days) | ||
if days == 1 | ||
"#{days} day" | ||
else | ||
"#{days} days" | ||
end | ||
end | ||
|
||
def months_to_s(months) | ||
if months == 1 | ||
"#{months} month" | ||
else | ||
"#{months} months" | ||
end | ||
end | ||
|
||
def render(context) | ||
total_days = days_from_seconds(context) | ||
days = Integer(total_days % DAYS_PER_MONTHS) | ||
months = Integer((total_days - days) / DAYS_PER_MONTHS) | ||
|
||
if months == 0 | ||
days_to_s(days) | ||
else | ||
"#{months_to_s(months)} and #{days_to_s(days)}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Liquid::Template.register_tag('duration_pms', Jekyll::Tags::DurationPMsTag) | ||
Liquid::Template.register_tag('duration_humanized', Jekyll::Tags::DurationHumanizedTag) |
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