Skip to content

Commit

Permalink
Choose a random date of birth
Browse files Browse the repository at this point in the history
  • Loading branch information
sLoPPydrive authored and drallieiv committed Jun 5, 2017
1 parent d802027 commit 50816ac
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions ptc-api/src/main/java/com/kinancity/api/model/AccountData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
* Information about a PTC account
*
*
* @author drallieiv
*
*/
Expand All @@ -31,27 +31,25 @@ public class AccountData implements Cloneable {
private String password;

// String Date of birth as YYYY-MM-DD
private String dob = "1985-01-16";
private String dob;

private String country = "US";

private SimpleDateFormat dobFormat = new SimpleDateFormat("yyyy-MM-dd");

public AccountData() {

this(null, null, null, null, null);
}

public AccountData(String username, String email, String password) {
this.username = username;
this.email = email;
this.password = password;
this(username, email, password, null, null);
}

public AccountData(String username, String email, String password, String dob, String country) {
this.username = username;
this.email = email;
this.password = password;
this.dob = dob;
setDob(dob != null ? dob : chooseRandomDateOfBirth());
this.country = country;
}

Expand Down Expand Up @@ -84,4 +82,29 @@ public String toString() {
return "AccountData [" + (username != null ? "username=" + username + ", " : "") + (email != null ? "email=" + email + ", " : "") + (password != null ? "password=" + password + ", " : "") + (dob != null ? "dob=" + dob + ", " : "") + (country != null ? "country=" + country : "") + "]";
}

private String chooseRandomDateOfBirth() {
Random generator = new Random();
// year: 1970 to 2000
int y = generator.nextInt(30) + 1970;
// month: 1 to 12
int m = generator.nextInt(12) + 1;
// day: depending on month
int maxDays;
switch (m) {
case 2:
maxDays = 28;
break;
case 4:
case 6:
case 9:
case 11:
maxDays = 30;
break;
default:
maxDays = 31;
}
int d = generator.nextInt(maxDays) + 1;
return String.format("%04d-%02d-%02d", y, m, d);
}

}

0 comments on commit 50816ac

Please sign in to comment.