Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## [Unreleased]

Fixes:
- Fix Denmark to ignore a `-` 🇩🇰

## [1.3.1] - 2026-03-24

Fixes:
Expand Down
7 changes: 5 additions & 2 deletions lib/tin_valid/denmark_tin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(tin:, birth_date: nil)
def valid?
match = MATCHER.match(tin)
return false unless match
return false if tin == "0000000000"
return false if normalized_tin == "0000000000"

if birth_date
year = "#{birth_century}#{match[:year]}"
Expand All @@ -35,6 +35,7 @@ def valid?
(?<day>[0-3][0-9])
(?<month>[0-1][0-9])
(?<year>[0-9]{2})
-?
(?<serial>
[0-9]{3}
(?<check>[0-9])
Expand All @@ -43,6 +44,8 @@ def valid?
}x
private_constant :MATCHER

def normalized_tin = @normalized_tin ||= tin.sub("-", "")

def birth_century = birth_date.strftime("%Y")[..1]
def birth_year = birth_date.year

Expand All @@ -51,7 +54,7 @@ def checksum
weights =
[4, 3, 2, 7, 6, 5, 4, 3, 2]
.each_with_index
.map { |char, index| char.to_i * tin[index].to_i }
.map { |char, index| char.to_i * normalized_tin[index].to_i }

# 2. Add up the results of the above multiplications;
sum = weights.sum
Expand Down
1 change: 1 addition & 0 deletions spec/tin_valid/denmark_tin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
describe "#valid?" do
valid_values = [
["0101111113", nil],
["010111-1113", nil],
["0101111113", Date.new(1911, 1, 1)],
["2808784028", nil],
["2808784028", Date.new(1978, 8, 28)],
Expand Down
Loading