jekyll_time_since 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -8
- data/CHANGELOG.md +3 -0
- data/README.md +34 -38
- data/Rakefile +1 -3
- data/jekyll_time_since.gemspec +20 -29
- data/lib/jekyll_time_since/version.rb +1 -3
- data/lib/jekyll_time_since.rb +18 -66
- data/spec/jekyll_time_since_spec.rb +14 -10
- data/spec/status_persistence.txt +1 -1
- metadata +7 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0668a30bfe9ba5327d29451e667484bff0a74e5159c3a1be8a94f8b250d813cd'
|
4
|
+
data.tar.gz: 594a56810f767dfa4eb4e77a0c32d8394465792b03f1aa80f988bee2c1e27b90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 887f887e114a7256676190995521d2468c3616d86fc82a3e8fd37ac05151dedf65e80ed4f5d7f145f3beff6ae3e7108c07e426fa860352275afc91813f550610
|
7
|
+
data.tar.gz: 6553172ec5f0f2c8043bfee170fec0b0878e969684b89ec65f9d9bc8020c5e9cf73065705264058312f0e3a45a581e8fd5b4d58cd3b4469554f7ec92d380b5b8
|
data/.rubocop.yml
CHANGED
@@ -1,20 +1,16 @@
|
|
1
|
-
require: rubocop-jekyll
|
2
|
-
inherit_gem:
|
3
|
-
rubocop-jekyll: .rubocop.yml
|
4
|
-
|
5
1
|
AllCops:
|
6
2
|
Exclude:
|
7
3
|
- vendor/**/*
|
8
4
|
- Gemfile*
|
9
|
-
- '*.gemspec'
|
5
|
+
- '*.gemspec'
|
10
6
|
NewCops: enable
|
11
7
|
TargetRubyVersion: 2.6
|
12
8
|
|
13
9
|
Layout/LineLength:
|
14
10
|
Max: 150
|
15
11
|
|
16
|
-
|
17
|
-
|
12
|
+
Style/FrozenStringLiteralComment:
|
13
|
+
Enabled: false
|
18
14
|
|
19
|
-
|
15
|
+
Style/MutableConstant:
|
20
16
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -26,10 +26,6 @@ And then execute:
|
|
26
26
|
|
27
27
|
$ bundle install
|
28
28
|
|
29
|
-
Or install it yourself as:
|
30
|
-
|
31
|
-
$ gem install jekyll_time_since
|
32
|
-
|
33
29
|
|
34
30
|
## Usage
|
35
31
|
|
@@ -42,40 +38,40 @@ The date and time strings can be surrounded with quotes, double quotes, or not.
|
|
42
38
|
Time zone can be omitted, or specified as GMT, Z, or +/- HHMM.
|
43
39
|
|
44
40
|
```
|
45
|
-
{
|
46
|
-
{
|
47
|
-
{
|
48
|
-
{
|
49
|
-
|
50
|
-
{
|
51
|
-
{
|
52
|
-
{
|
53
|
-
{
|
54
|
-
|
55
|
-
{
|
56
|
-
{
|
57
|
-
{
|
58
|
-
{
|
59
|
-
|
60
|
-
{
|
61
|
-
{
|
62
|
-
{
|
63
|
-
{
|
64
|
-
|
65
|
-
{
|
66
|
-
{
|
67
|
-
{
|
68
|
-
{
|
69
|
-
|
70
|
-
{
|
71
|
-
{
|
72
|
-
{
|
73
|
-
{
|
74
|
-
|
75
|
-
{
|
76
|
-
{
|
77
|
-
{
|
78
|
-
{
|
41
|
+
{{ "1959" | years_since }} {{ '1959' | years_since }}
|
42
|
+
{{ "1959-02-03" | years_since }} {{ '1959-02-03' | years_since }}
|
43
|
+
{{ "1959-02-03T01:02" | years_since }} {{ '1959-02-03T01:02' | years_since }}
|
44
|
+
{{ "1959-02-03T01:02:00Z" | years_since }} {{ "1959-02-03T01:02:00-0400" | years_since }}
|
45
|
+
|
46
|
+
{{ "1959" | months_since }} {{ months_since '1959' }}
|
47
|
+
{{ "1959-02-03" months_since }} {{ '1959-02-03' | months_since }}
|
48
|
+
{{ "1959-02-03T01:02" | months_since }} {{ '1959-02-03T01:02' | months_since }}
|
49
|
+
{{ "1959-02-03T01:02:00Z" | months_since }} {{ "1959-02-03T01:02:00-0400" | months_since }}
|
50
|
+
|
51
|
+
{{ "1959" | weeks_since }} {{ '1959' | weeks_since }}
|
52
|
+
{{ "1959-02-03" | weeks_since }} {{ '1959-02-03' | weeks_since }}
|
53
|
+
{{ "1959-02-03T01:02" | weeks_since }} {{ '1959-02-03T01:02' | weeks_since }}
|
54
|
+
{{ "1959-02-03T01:02:00Z" | weeks_since }} {{ "1959-02-03T01:02:00-0400" | weeks_since }}
|
55
|
+
|
56
|
+
{{ "1959" | days_since }} {{ '1959' | days_since }}
|
57
|
+
{{ "1959-02-03" | days_since }} {{ '1959-02-03' | days_since }}
|
58
|
+
{{ "1959-02-03T01:02" | days_since }} {{ '1959-02-03T01:02' | days_since }}
|
59
|
+
{{ "1959-02-03T01:02:00Z" | days_since }} {{ "1959-02-03T01:02:00-0400" | days_since }}
|
60
|
+
|
61
|
+
{{ "1959" | hours_since}} {{ '1959' | hours_since }}
|
62
|
+
{{ "1959-02-03" | hours_since }} {{ '1959-02-03' | hours_since }}
|
63
|
+
{{ "1959-02-03T01:02" | hours_since }} {{ '1959-02-03T01:02' | hours_since }}
|
64
|
+
{{ "1959-02-03T01:02:00Z" | hours_since }} {{ "1959-02-03T01:02:00-0400" | hours_since }}
|
65
|
+
|
66
|
+
{{ "1959" | minutes_since }} {{ '1959' | minutes_since }}
|
67
|
+
{{ "1959-02-03" | minutes_since }} {{ '1959-02-03' | minutes_since }}
|
68
|
+
{{ "1959-02-03T01:02" | minutes_since }} {{ '1959-02-03T01:02' | minutes_since }}
|
69
|
+
{{ "1959-02-03T01:02:00Z" | minutes_since }} {{ "1959-02-03T01:02:00-0400" | minutes_since }}
|
70
|
+
|
71
|
+
{{ "1959" | seconds_since }} {{ '1959' | seconds_since }}
|
72
|
+
{{ "1959-02-03" | seconds_since }} {{ '1959-02-03' | seconds_since }}
|
73
|
+
{{ "1959-02-03T01:02" | seconds_since }} {{ '1959-02-03T01:02' | seconds_since }}
|
74
|
+
{{ seconds_since "1959-02-03T01:02:00" }} {{ seconds_since '1959-02-03T01:02:00' }}
|
79
75
|
```
|
80
76
|
|
81
77
|
|
data/Rakefile
CHANGED
data/jekyll_time_since.gemspec
CHANGED
@@ -1,44 +1,35 @@
|
|
1
|
-
|
1
|
+
require_relative 'lib/jekyll_time_since/version'
|
2
2
|
|
3
|
-
require_relative "lib/jekyll_time_since/version"
|
4
|
-
|
5
|
-
# rubocop:disable Metrics/BlockLength
|
6
3
|
Gem::Specification.new do |spec|
|
7
|
-
github =
|
4
|
+
github = 'https://github.com/mslinn/jekyll_time_since'
|
8
5
|
|
9
|
-
spec.authors = [
|
10
|
-
spec.bindir =
|
6
|
+
spec.authors = ['Michael Slinn']
|
7
|
+
spec.bindir = 'exe'
|
11
8
|
spec.description = <<~END_OF_DESC
|
12
|
-
|
9
|
+
jekyll_time_since is a Jekyll plugin that provides new Liquid tags called years_since, months_since, days_since, hours_since, minutes_since and seconds_since.
|
13
10
|
END_OF_DESC
|
14
|
-
spec.email = [
|
11
|
+
spec.email = ['email@email.com']
|
15
12
|
|
16
13
|
# Specify which files should be added to the gem when it is released.
|
17
14
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files = Dir[
|
15
|
+
spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
|
19
16
|
|
20
|
-
spec.homepage =
|
21
|
-
spec.license =
|
17
|
+
spec.homepage = 'https://www.mslinn.com/blog/2020/12/30/jekyll-plugin-template-collection.html'
|
18
|
+
spec.license = 'MIT'
|
22
19
|
spec.metadata = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
'allowed_push_host' => 'https://rubygems.org',
|
21
|
+
'bug_tracker_uri' => "#{github}/issues",
|
22
|
+
'changelog_uri' => "#{github}/CHANGELOG.md",
|
23
|
+
'homepage_uri' => spec.homepage,
|
24
|
+
'source_code_uri' => github,
|
28
25
|
}
|
29
|
-
spec.name =
|
30
|
-
spec.require_paths = [
|
31
|
-
spec.required_ruby_version =
|
32
|
-
spec.summary =
|
26
|
+
spec.name = 'jekyll_time_since'
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
spec.required_ruby_version = '>= 2.6.0'
|
29
|
+
spec.summary = 'jekyll_time_since is a Jekyll plugin that provides new Liquid tags called years_since, months_since, days_since, hours_since, minutes_since and seconds_since.'
|
33
30
|
spec.version = JekyllTimeSinceVersion::VERSION
|
34
31
|
|
35
|
-
spec.add_dependency
|
36
|
-
spec.add_dependency
|
37
|
-
|
38
|
-
spec.add_development_dependency "debase"
|
39
|
-
# spec.add_development_dependency "rubocop-jekyll"
|
40
|
-
# spec.add_development_dependency "rubocop-rake"
|
41
|
-
# spec.add_development_dependency "rubocop-rspec"
|
42
|
-
spec.add_development_dependency "ruby-debug-ide"
|
32
|
+
spec.add_dependency 'jekyll', '>= 3.5.0'
|
33
|
+
spec.add_dependency 'jekyll_plugin_logger'
|
43
34
|
end
|
44
35
|
# rubocop:enable Metrics/BlockLength
|
data/lib/jekyll_time_since.rb
CHANGED
@@ -1,73 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require "time"
|
5
|
-
require_relative "jekyll_time_since/version"
|
1
|
+
require 'jekyll_plugin_logger'
|
2
|
+
require 'time'
|
3
|
+
require_relative 'jekyll_time_since/version'
|
6
4
|
|
7
5
|
module JekyllTimeSinceName
|
8
|
-
PLUGIN_NAME =
|
6
|
+
PLUGIN_NAME = 'jekyll_time_since'
|
9
7
|
end
|
10
8
|
|
11
9
|
# These tags all work in a similar manner; they accept one parameter,
|
12
10
|
# which is either a date string (`YYYY-MM-dd`) or an
|
13
11
|
# [ISO 8601-1:2019](https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations) datetime string (`YYYY-MM-ddThh:mm`).
|
12
|
+
#
|
14
13
|
# Just a year can be specified, which implies Jan 1 at midnight.
|
15
14
|
# You can specify a time zone
|
16
15
|
# For more information, see https://ruby-doc.org/stdlib-2.7.2/libdoc/time/rdoc/Time.html
|
17
|
-
#
|
18
|
-
# The date and time strings can be surrounded with quotes, double quotes, or not.
|
19
|
-
# The following examples compute elapsed time since "the day the music died" (1959-02-03).
|
20
|
-
# See https://en.wikipedia.org/wiki/The_Day_the_Music_Died
|
21
|
-
#
|
22
|
-
# @example years_since
|
23
|
-
# Computes years since the date specified
|
24
|
-
# {% "1959" | years_since %} {% '1959' | years_since %}
|
25
|
-
# {% "1959-02-03" | years_since %} {% '1959-02-03' | years_since %}
|
26
|
-
# {% "1959-02-03T01:02:00" | years_since %} {% '1959-02-03T01:02:00' | years_since %}
|
27
|
-
# {% "1959-02-03T01:02:00Z" | years_since %} {% "1959-02-03T01:02:00-0400" | years_since %}
|
28
|
-
#
|
29
|
-
# @example months_since
|
30
|
-
# Computes months since the date specified
|
31
|
-
# {% "1959" | months_since %} {% months_since '1959' %}
|
32
|
-
# {% "1959-02-03" months_since %} {% '1959-02-03' | months_since %}
|
33
|
-
# {% "1959-02-03T01:02" | months_since %} {% '1959-02-03T01:02' | months_since %}
|
34
|
-
# {% "1959-02-03T01:02:00Z" | months_since %} {% "1959-02-03T01:02:00-0400" | months_since %}
|
35
|
-
#
|
36
|
-
# @example weeks_since
|
37
|
-
# Computes weeks since the date specified
|
38
|
-
# {% "1959" | weeks_since %} {% '1959' | weeks_since %}
|
39
|
-
# {% "1959-02-03" | weeks_since %} {% '1959-02-03' | weeks_since %}
|
40
|
-
# {% "1959-02-03T01:02:00" | weeks_since %} {% '1959-02-03T01:02:00' | weeks_since %}
|
41
|
-
# {% "1959-02-03T01:02:00Z" | weeks_since %} {% "1959-02-03T01:02:00-0400" | weeks_since %}
|
42
|
-
#
|
43
|
-
# @example days_since
|
44
|
-
# Computes days since the date specified
|
45
|
-
# {% "1959" | days_since %} {% '1959' | days_since %}
|
46
|
-
# {% "1959-02-03" | days_since %} {% '1959-02-03' | days_since %}
|
47
|
-
# {% "1959-02-03T01:02" | days_since %} {% '1959-02-03T01:02' | days_since %}
|
48
|
-
# {% "1959-02-03T01:02:00Z" | days_since %} {% "1959-02-03T01:02:00-0400" | days_since %}
|
49
|
-
#
|
50
|
-
# @example hours_since
|
51
|
-
# Computes hours since the date and time specified
|
52
|
-
# {% "1959" | hours_since%} {% '1959' | hours_since %}
|
53
|
-
# {% "1959-02-03" | hours_since %} {% '1959-02-03' | hours_since %}
|
54
|
-
# {% "1959-02-03T01:02" | hours_since %} {% '1959-02-03T01:02' | hours_since %}
|
55
|
-
# {% "1959-02-03T01:02:00Z" | hours_since %} {% "1959-02-03T01:02:00-0400" | hours_since %}
|
56
|
-
#
|
57
|
-
# @example minutes_since
|
58
|
-
# Computes minutes since the date and time specified
|
59
|
-
# {% "1959" | minutes_since %} {% '1959' | minutes_since %}
|
60
|
-
# {% "1959-02-03" | minutes_since %} {% '1959-02-03' | minutes_since %}
|
61
|
-
# {% "1959-02-03T01:02" | minutes_since %} {% '1959-02-03T01:02' | minutes_since %}
|
62
|
-
# {% "1959-02-03T01:02:00Z" | minutes_since %} {% "1959-02-03T01:02:00-0400" | minutes_since %}
|
63
|
-
#
|
64
|
-
# @example seconds_since
|
65
|
-
# Computes seconds since the date and time specified
|
66
|
-
# {% "1959" | seconds_since %} {% '1959' | seconds_since %}
|
67
|
-
# {% "1959-02-03" | seconds_since %} {% '1959-02-03' | seconds_since %}
|
68
|
-
# {% "1959-02-03T01:02" | seconds_since %} {% '1959-02-03T01:02' | seconds_since %}
|
69
|
-
# {% seconds_since "1959-02-03T01:02:00" %} {% seconds_since '1959-02-03T01:02:00' %}
|
70
|
-
|
71
16
|
module TimeSince
|
72
17
|
@logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
|
73
18
|
|
@@ -75,7 +20,7 @@ module TimeSince
|
|
75
20
|
# @return [integer] the number of years since the input.
|
76
21
|
def years_since(string)
|
77
22
|
now = DateTime.now
|
78
|
-
string +=
|
23
|
+
string += '-01-01' unless string.include?('-')
|
79
24
|
date = Time.parse(string)
|
80
25
|
years = now.year - date.year
|
81
26
|
years -= 1 if date.month > now.month || (date.month >= now.month && date.day > now.day)
|
@@ -83,19 +28,26 @@ module TimeSince
|
|
83
28
|
end
|
84
29
|
|
85
30
|
def months_since(string)
|
86
|
-
string +=
|
31
|
+
string += '-01-01' unless string.include?('-')
|
87
32
|
date1 = Date.parse(string)
|
88
33
|
|
89
34
|
date2 = Time.new.to_date
|
90
|
-
((date2 - date1).to_f / 365 * 12).round
|
35
|
+
months = ((date2 - date1).to_f / 365 * 12).round
|
36
|
+
months -= 1 if date2.day > date1.day
|
37
|
+
months
|
91
38
|
end
|
92
39
|
|
93
40
|
def weeks_since(string)
|
94
|
-
days_since(string)
|
41
|
+
result = days_since(string)
|
42
|
+
result.to_i / 7
|
95
43
|
end
|
96
44
|
|
97
45
|
def days_since(string)
|
98
|
-
|
46
|
+
string += '-01-01' unless string.include?('-')
|
47
|
+
date1 = Date.parse(string)
|
48
|
+
|
49
|
+
date2 = Time.new.to_date
|
50
|
+
(date2 - date1).to_i
|
99
51
|
end
|
100
52
|
|
101
53
|
def hours_since(string)
|
@@ -107,7 +59,7 @@ module TimeSince
|
|
107
59
|
end
|
108
60
|
|
109
61
|
def seconds_since(string)
|
110
|
-
string +=
|
62
|
+
string += '-01-01' unless string.include?('-')
|
111
63
|
(Time.new - Time.parse(string)).to_i
|
112
64
|
end
|
113
65
|
end
|
@@ -1,17 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require_relative "../lib/jekyll_time_since"
|
1
|
+
require 'date'
|
2
|
+
require_relative '../lib/jekyll_time_since'
|
4
3
|
|
5
4
|
RSpec.describe(TimeSince) do
|
6
5
|
include TimeSince
|
7
|
-
it "Computes years" do
|
8
|
-
years_since("1956")
|
9
|
-
years_since("1956-10-15")
|
10
6
|
|
11
|
-
|
12
|
-
|
7
|
+
def py_time(unit, date)
|
8
|
+
`python3 bin/time_since.py #{unit} #{date}`.strip.to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'computes time since' do
|
12
|
+
expect(py_time('year', '1956-01-01')).to eq(years_since('1956'))
|
13
|
+
expect(py_time('year', '1956-10-15')).to eq(years_since('1956-10-15'))
|
14
|
+
|
15
|
+
expect(py_time('month', '1956-01-01')).to eq(months_since('1956'))
|
16
|
+
expect(py_time('month', '1956-10-15')).to eq(months_since('1956-10-15'))
|
13
17
|
|
14
|
-
weeks_since(
|
15
|
-
weeks_since(
|
18
|
+
expect(py_time('week', '1956-01-01')).to eq(weeks_since('1956'))
|
19
|
+
expect(py_time('week', '1956-10-15')).to eq(weeks_since('1956-10-15'))
|
16
20
|
end
|
17
21
|
end
|
data/spec/status_persistence.txt
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll_time_since
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Slinn
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -38,38 +38,10 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: debase
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: ruby-debug-ide
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
41
|
description: 'jekyll_time_since is a Jekyll plugin that provides new Liquid tags called
|
70
42
|
years_since, months_since, days_since, hours_since, minutes_since and seconds_since.
|
71
43
|
|
72
|
-
'
|
44
|
+
'
|
73
45
|
email:
|
74
46
|
- email@email.com
|
75
47
|
executables: []
|
@@ -96,7 +68,7 @@ metadata:
|
|
96
68
|
changelog_uri: https://github.com/mslinn/jekyll_time_since/CHANGELOG.md
|
97
69
|
homepage_uri: https://www.mslinn.com/blog/2020/12/30/jekyll-plugin-template-collection.html
|
98
70
|
source_code_uri: https://github.com/mslinn/jekyll_time_since
|
99
|
-
post_install_message:
|
71
|
+
post_install_message:
|
100
72
|
rdoc_options: []
|
101
73
|
require_paths:
|
102
74
|
- lib
|
@@ -111,8 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
83
|
- !ruby/object:Gem::Version
|
112
84
|
version: '0'
|
113
85
|
requirements: []
|
114
|
-
rubygems_version: 3.
|
115
|
-
signing_key:
|
86
|
+
rubygems_version: 3.3.3
|
87
|
+
signing_key:
|
116
88
|
specification_version: 4
|
117
89
|
summary: jekyll_time_since is a Jekyll plugin that provides new Liquid tags called
|
118
90
|
years_since, months_since, days_since, hours_since, minutes_since and seconds_since.
|