tempora 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/locales/de.yml +71 -0
- data/config/locales/en.yml +74 -0
- data/lib/month.rb +2 -2
- data/lib/quarter.rb +1 -1
- data/lib/tempora/formatter.rb +64 -0
- data/lib/tempora/version.rb +1 -1
- data/lib/tempora.rb +9 -2
- data/lib/week.rb +1 -1
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a46ecbe3533d7f668ce4a69e5b6770f7ddd652d360b16fd2a8eca24a762807f
|
4
|
+
data.tar.gz: 20841d06370d1df8da36f26bce276114c3917fe2c0b9f8ff46bed644aada8061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37bc14b3d16dab1f93f3f1319fb012ef5fafed211f09ed30ef446fda5f36187611b322e6b7bec11e73dfa9ba0ef34c339b897a4eabe09cee4e4e9de4f53171a9
|
7
|
+
data.tar.gz: 4f143cccd749e6157cc7cf954b5f9a7ca45246c4822ef7bfcf7cd8f239022eee7cb0346ac81865c539c574c67cff548d3a7de2c7c8a0202786a57b7c5a94c92d
|
@@ -0,0 +1,71 @@
|
|
1
|
+
---
|
2
|
+
de:
|
3
|
+
defaults: &defaults
|
4
|
+
month_names:
|
5
|
+
[~, Januar, Februar, März, April, Mai, Juni, Juli, August, September, Oktober, November, Dezember]
|
6
|
+
abbr_month_names:
|
7
|
+
[~, Jan, Feb, Mär, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez]
|
8
|
+
day_names:
|
9
|
+
[Sonntag, Montag, Dienstag, Mittwoch, Donnerstag, Freitag, Samstag]
|
10
|
+
abbr_day_names:
|
11
|
+
[So, Mo, Di, Mi, Do, Fr, Sa]
|
12
|
+
formats:
|
13
|
+
default: "%d.%m.%Y"
|
14
|
+
long: "%e. %B %Y"
|
15
|
+
short: "%e. %b"
|
16
|
+
order:
|
17
|
+
- :day
|
18
|
+
- :month
|
19
|
+
- :year
|
20
|
+
|
21
|
+
date:
|
22
|
+
<<: *defaults
|
23
|
+
time:
|
24
|
+
<<: *defaults
|
25
|
+
|
26
|
+
timeperiod:
|
27
|
+
year: "Jahr"
|
28
|
+
quarter: "Quartal"
|
29
|
+
month: "Monat"
|
30
|
+
week: "Woche"
|
31
|
+
|
32
|
+
same_day:
|
33
|
+
default: # 01.10.2015 10:30 - 12:45
|
34
|
+
from: "%d.%m.%Y, %H:%M"
|
35
|
+
till: "%H:%M"
|
36
|
+
long: # 1. Oktober 2015, 10:30 - 12:45 Uhr
|
37
|
+
from: "%-e. %B %Y, %H:%M"
|
38
|
+
till: "%H:%M Uhr"
|
39
|
+
short: # 1. Okt 2015, 10:30 - 12:45
|
40
|
+
from: "%-e. %b %y, %H:%M"
|
41
|
+
till: "%H:%M"
|
42
|
+
same_month:
|
43
|
+
default: # 01. - 03.10.2015
|
44
|
+
from: "%d."
|
45
|
+
till: "%d.%m.%Y"
|
46
|
+
long: # 1. - 3. Oktober 2015
|
47
|
+
from: "%-e."
|
48
|
+
till: "%-e. %B %Y"
|
49
|
+
short: # 1. - 3. Okt 15
|
50
|
+
from: "%-e."
|
51
|
+
till: "%-e. %b %y"
|
52
|
+
same_year:
|
53
|
+
default: # 01.07 - 3.10.2015
|
54
|
+
from: "%d.%m."
|
55
|
+
till: "%d.%m.%Y"
|
56
|
+
long: # 1. Juli - 3. Oktober 2015
|
57
|
+
from: "%-e. %B"
|
58
|
+
till: "%-e. %B %Y"
|
59
|
+
short: # 1. Jul - 3. Okt 15
|
60
|
+
from: "%-e. %b"
|
61
|
+
till: "%-e. %b %y"
|
62
|
+
different_year:
|
63
|
+
default: # 01.07.2015 - 03.10.2016
|
64
|
+
from: "%d.%m.%Y"
|
65
|
+
till: "%d.%m.%Y"
|
66
|
+
long: # 1. Juli 2015 - 3. Oktober 2016
|
67
|
+
from: "%-e. %B %Y"
|
68
|
+
till: "%-e. %B %Y"
|
69
|
+
short: # 1. Jul 15 - 3. Okt 16
|
70
|
+
from: "%-e. %b %y"
|
71
|
+
till: "%-e. %b %y"
|
@@ -0,0 +1,74 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
defaults: &defaults
|
4
|
+
month_names:
|
5
|
+
[~, January, February, March, April, May, June, July, August, September, October, November, December]
|
6
|
+
abbr_month_names:
|
7
|
+
[~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
|
8
|
+
day_names:
|
9
|
+
[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
|
10
|
+
abbr_day_names:
|
11
|
+
[Su, Mo, Tu, We, Th, Fr, Sa]
|
12
|
+
formats:
|
13
|
+
default: "%Y-%m-%d"
|
14
|
+
long: "%B %d, %Y"
|
15
|
+
short: "%b %d"
|
16
|
+
order:
|
17
|
+
- :day
|
18
|
+
- :month
|
19
|
+
- :year
|
20
|
+
|
21
|
+
date:
|
22
|
+
<<: *defaults
|
23
|
+
time:
|
24
|
+
<<: *defaults
|
25
|
+
|
26
|
+
timeperiod:
|
27
|
+
year: "Year"
|
28
|
+
quarter: "Quarter"
|
29
|
+
month: "Month"
|
30
|
+
week: "Week"
|
31
|
+
|
32
|
+
same_day:
|
33
|
+
default: # 2015-10-03, 10:30 - 12:45
|
34
|
+
from: "%Y-%m-%d, %H:%M"
|
35
|
+
till: "%H:%M"
|
36
|
+
long: # October 03, 2015, 10:30 - 12:45
|
37
|
+
from: "%B %d, %Y, %H:%M"
|
38
|
+
till: "%H:%M"
|
39
|
+
short: # Oct 03, 10:30 - 12:45
|
40
|
+
from: "%b %d, %H:%M"
|
41
|
+
till: "%H:%M"
|
42
|
+
time:
|
43
|
+
from: "%H:%M"
|
44
|
+
till: "%H:%M"
|
45
|
+
same_month:
|
46
|
+
default: # 2015-10-03 - 09
|
47
|
+
from: "%Y-%m-%d"
|
48
|
+
till: "%d"
|
49
|
+
long: # October 03 - 09, 2015
|
50
|
+
from: "%B %d"
|
51
|
+
till: "%d, %Y"
|
52
|
+
short: # Oct 03 - 09
|
53
|
+
from: "%b %d"
|
54
|
+
till: "%d"
|
55
|
+
same_year:
|
56
|
+
default: # 2015-10-03 - 11-30
|
57
|
+
from: "%Y-%m-%d"
|
58
|
+
till: "%m-%d"
|
59
|
+
long: # October 10 - November 20, 2015
|
60
|
+
from: "%B %d"
|
61
|
+
till: "%B %d, %Y"
|
62
|
+
short: # Oct 10 - Nov 20, 15
|
63
|
+
from: "%b %d"
|
64
|
+
till: "%b %d, %y"
|
65
|
+
different_year:
|
66
|
+
default: # 2015-10-10 - 2016-11-20
|
67
|
+
from: "%Y-%m-%d"
|
68
|
+
till: "%Y-%m-%d"
|
69
|
+
long: # October 10, 2015 - November 20, 2016
|
70
|
+
from: "%B %d, %Y"
|
71
|
+
till: "%B %d, %Y"
|
72
|
+
short: # Oct 10, 15 - Nov 20, 16
|
73
|
+
from: "%b %d, %y"
|
74
|
+
till: "%b %d, %y"
|
data/lib/month.rb
CHANGED
data/lib/quarter.rb
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Tempora
|
2
|
+
class TimePeriodFormatter
|
3
|
+
I18nScopeKeys = %i(same_day same_month same_year different_year).freeze
|
4
|
+
I18nScopeKeysIdentifiers = { begin: :from, end: :till}
|
5
|
+
|
6
|
+
# format: [:default, :short, :long] -> see I18n.localize
|
7
|
+
def initialize(timeperiod, format: :long)
|
8
|
+
@timeperiod = timeperiod
|
9
|
+
@format = format
|
10
|
+
end
|
11
|
+
|
12
|
+
def render
|
13
|
+
from = I18n.l @timeperiod.begin, format: format_for(:from)
|
14
|
+
till = I18n.l @timeperiod.end, format: format_for(:till)
|
15
|
+
[from, till].reject(&:empty?).join ' – '
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def format_for(key)
|
21
|
+
I18n.t key, scope: [:timeperiod, scope_key, @format]
|
22
|
+
end
|
23
|
+
|
24
|
+
def scope_key
|
25
|
+
I18nScopeKeyFinder.call(@timeperiod)
|
26
|
+
end
|
27
|
+
|
28
|
+
class I18nScopeKeyFinder
|
29
|
+
def initialize(timeperiod)
|
30
|
+
@timeperiod = timeperiod
|
31
|
+
end
|
32
|
+
|
33
|
+
def call
|
34
|
+
I18nScopeKeys.find { |scope_key| send(:"#{scope_key}?") }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.call(timeperiod)
|
38
|
+
new(timeperiod).call
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def different_year?
|
44
|
+
!same_year?
|
45
|
+
end
|
46
|
+
|
47
|
+
def same_year?
|
48
|
+
same? :year
|
49
|
+
end
|
50
|
+
|
51
|
+
def same_month?
|
52
|
+
same? :year, :month
|
53
|
+
end
|
54
|
+
|
55
|
+
def same_day?
|
56
|
+
same? :year, :month, :day
|
57
|
+
end
|
58
|
+
|
59
|
+
def same?(*methods)
|
60
|
+
methods.all? { |m| @timeperiod.begin.send(m) == @timeperiod.end.send(m) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/tempora/version.rb
CHANGED
data/lib/tempora.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "i18n"
|
3
4
|
require_relative "tempora/version"
|
4
5
|
require_relative "timeperiod"
|
5
6
|
require_relative "year"
|
6
7
|
require_relative "month"
|
7
8
|
require_relative "week"
|
8
9
|
require_relative "quarter"
|
9
|
-
|
10
|
+
require_relative "tempora/formatter"
|
10
11
|
|
11
12
|
module Tempora
|
12
13
|
class Error < StandardError; end
|
14
|
+
|
15
|
+
def self.load_i18n
|
16
|
+
I18n.load_path += Dir[File.expand_path("../../config/locales/*.yml", __FILE__)]
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
|
-
|
20
|
+
Tempora.load_i18n if defined?(I18n)
|
21
|
+
|
22
|
+
Object.include Tempora
|
data/lib/week.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tempora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Power
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
11
|
-
dependencies:
|
10
|
+
date: 2025-03-16 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: i18n
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
12
26
|
description: Tempora is a lightweight Ruby library for handling months, weeks, quarters,
|
13
27
|
and years with intuitive date-based calculations and range support.
|
14
28
|
email:
|
@@ -20,9 +34,12 @@ files:
|
|
20
34
|
- LICENSE.txt
|
21
35
|
- README.md
|
22
36
|
- Rakefile
|
37
|
+
- config/locales/de.yml
|
38
|
+
- config/locales/en.yml
|
23
39
|
- lib/month.rb
|
24
40
|
- lib/quarter.rb
|
25
41
|
- lib/tempora.rb
|
42
|
+
- lib/tempora/formatter.rb
|
26
43
|
- lib/tempora/has_days.rb
|
27
44
|
- lib/tempora/has_months.rb
|
28
45
|
- lib/tempora/has_time.rb
|
@@ -55,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
72
|
- !ruby/object:Gem::Version
|
56
73
|
version: '0'
|
57
74
|
requirements: []
|
58
|
-
rubygems_version: 3.6.
|
75
|
+
rubygems_version: 3.6.6
|
59
76
|
specification_version: 4
|
60
77
|
summary: Tempora is a lightweight Ruby library for handling months, weeks, quarters,
|
61
78
|
and years.
|