persian_date 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/persian_date.rb +44 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c599994722dd5973147e765848ee86e29a4661c3ca7a5b57786403ee76566341
4
+ data.tar.gz: 1b2135b0faa2361e5d52e70a0174a23b855b7120159b0c67532d13a8e1c5bb84
5
+ SHA512:
6
+ metadata.gz: 4c0d3f2dab34f7fbf563f8d0d0fc9cd95f3e8926b0a9de993ac7a0cd4e9f09a857ea1e167162630f8e29566bbfd11876f4f4d4c598ba4dfa653175c85bec08ad
7
+ data.tar.gz: 4a8139afb5844a50c7b40a3e30641de67b620255a6216fd32f6bfd4715e7c438413cbb71405f8a683c16dbcfd24bac92cac8406934ee2191689ee714281ca23f
@@ -0,0 +1,44 @@
1
+ require "date"
2
+
3
+ class DateTime
4
+
5
+ GDaysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
6
+ JDaysInMonth = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29]
7
+
8
+ def to_persian
9
+
10
+ tmp=0
11
+ gy = self.year - 1600
12
+ gm = self.month - 1
13
+ gd = self.day - 1
14
+ g_day_no = 365*gy + (gy+3)/4 - (gy+99)/100 + (gy+399)/400
15
+ gm.times { |i| g_day_no += GDaysInMonth[i] }
16
+ g_day_no += 1 if gm > 1 && ((gy%4 == 0 && gy%100 != 0) || (gy%400 == 0))
17
+ g_day_no += gd
18
+
19
+ j_day_no = g_day_no-79
20
+ j_np = j_day_no/12053
21
+ j_day_no %= 12053
22
+ jy = 979 + 33 * j_np + 4*(j_day_no/1461)
23
+ j_day_no %= 1461
24
+
25
+ if (j_day_no >= 366)
26
+ jy += (j_day_no - 1)/365
27
+ j_day_no = (j_day_no - 1) % 365
28
+ end
29
+
30
+ 11.times do |i|
31
+ if j_day_no >= JDaysInMonth[i]
32
+ j_day_no -= JDaysInMonth[i]
33
+ tmp = i + 1
34
+ else
35
+ tmp = i
36
+ break
37
+ end
38
+ end
39
+ jm = tmp + 1
40
+ jd = j_day_no + 1
41
+
42
+ [jy, jm, jd]
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: persian_date
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hamidreza Safari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/persian_date.rb
20
+ homepage:
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.6
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: persian_date is an awesome gem
43
+ test_files: []