Skip to content

Commit

Permalink
Merge pull request #21 from personnummer/v3
Browse files Browse the repository at this point in the history
V3
  • Loading branch information
Johannestegner authored Jun 18, 2020
2 parents 28e792d + daa7ab2 commit 403d038
Show file tree
Hide file tree
Showing 10 changed files with 554 additions and 217 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2019 - Personnummer and Contributors
Copyright (c) 2017-2020 - Personnummer and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
89 changes: 79 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,91 @@
# Personnummer

[![Build Status](https://travis-ci.org/personnummer/java.svg?branch=master)](https://travis-ci.org/personnummer/java)
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/personnummer/java/Test)](https://github.com/personnummer/java/actions)

Validate Swedish personal identity numbers
Validate Swedish personal identity numbers.

## Example
## Installation

```java
class Test {
public void main(String[] args){
Personnummer.valid(6403273813L); // => True
Personnummer.valid("19130401+2931"); // => True
Add the github repository as a Maven or Gradle repository:

```xml
<dependency>
<groupId>dev.personnummer</groupId>
<artifactId>personnummer</artifactId>
<version>3.*.*</version>
</dependency>
```

```groovy
plugins {
id 'maven'
}
repositories {
maven {
url "https://github.com/personnummer/java:personnummer"
}
}
dependencies {
configuration("dev.personnummer:personnummer")
}
```

For more information on how to install and authenticate with github packages, check [this link](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages).

## Examples

### Validation

```java
import dev.personnummer.*;

class Test
{
public void TestValidation()
{
Personnummer.valid("191212121212"); // => True
Personnummer.valid("12121+21212"); // => True
Personnummer.valid("2012121-21212"); // => True
}
}
```

### Format

```java
// Short format (YYMMDD-XXXX)
(new Personnummer("1212121212")).format();
// => 121212-1212

// Short format for 100+ years old
(new Personnummer("191212121212")).format();
//=> 121212+1212

// Long format (YYYYMMDDXXXX)
Personnummer.parse("1212121212").format(true);
//=> 201212121212
```

### Age

```java
(new Personnummer("1212121212")).getAge();
//=> 7
```

### Get sex

```java
(new Personnummer("1212121212")).isMale();
//=> true
Personnummer.parse("1212121212").isFemale();
//=> false
```

See [`src/test/java/PersonnummerTest.java`](src/test/java/PersonnummerTest.java) for more examples.
See `src/test//PersonnummerTest.java` for more examples.

## License

[MIT](LICENSE)
[MIT](https://github.com/personnummer/java/blob/master/LICENSE)
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
plugins {
id("maven-publish")
id 'maven-publish'
id 'java-library'
id 'java'
}

apply plugin: 'java-library'
apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
jcenter()
mavenCentral()
}

dependencies {
testImplementation 'junit:junit:4.12'
testCompile ("junit:junit:4.12", "org.json:json:20200518")
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
testCompile('org.junit.jupiter:junit-jupiter:5.6.2', "org.json:json:20200518")
}


Expand All @@ -27,6 +26,7 @@ jar {
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
Expand Down
97 changes: 0 additions & 97 deletions src/main/java/Personnummer.java

This file was deleted.

12 changes: 12 additions & 0 deletions src/main/java/dev/personnummer/Options.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.personnummer;

public class Options {
public Options(boolean allowCoordinationNumber) {
this.allowCoordinationNumber = allowCoordinationNumber;
}

public Options() {
}

boolean allowCoordinationNumber = true;
}
Loading

0 comments on commit 403d038

Please sign in to comment.