Skip to content

Commit

Permalink
Merge ca2de32 into 8462c76
Browse files Browse the repository at this point in the history
  • Loading branch information
Cary-Xx committed Oct 16, 2019
2 parents 8462c76 + ca2de32 commit 03021f7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ dependencies {
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion

testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static Date parseDate(ArgumentMultimap argMultimap) throws ParseException
String date;
if (!dateField.isPresent()) {
LocalDateTime currentDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMM yyyy, H:mma");
date = currentDateTime.format(formatter);
} else {
date = dateField.get();
Expand Down
38 changes: 23 additions & 15 deletions src/main/java/seedu/address/model/expense/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,67 +89,75 @@ private static String convertDate(String date) {
LocalTime newTime;
LocalDate newDate;
LocalDateTime newDateTime;
String datePattern = "dd MMM yyyy";
String dateTimePattern = "dd MMM yyyy, H:mma";
if (date.matches(HMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("Hmm");
newTime = LocalTime.parse(date, formatter);
return newTime.format(DateTimeFormatter.ofPattern("H:mma"));
return appendDate(newTime).format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(HHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("HHmm");
formatter = DateTimeFormatter.ofPattern("Hmm");
newTime = LocalTime.parse(date, formatter);
return newTime.format(DateTimeFormatter.ofPattern("HH:mma"));
return appendDate(newTime).format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DMYYYY_REGEX)) {
formatter = DateTimeFormatter.ofPattern("d/M/yyyy");
newDate = LocalDate.parse(date, formatter);
return newDate.format(DateTimeFormatter.ofPattern("MMM dd, yyyy"));
return newDate.format(DateTimeFormatter.ofPattern(datePattern));
} else if (date.matches(DMMYYYY_REGEX)) {
formatter = DateTimeFormatter.ofPattern("d/MM/yyyy");
newDate = LocalDate.parse(date, formatter);
return newDate.format(DateTimeFormatter.ofPattern("MMM dd, yyyy"));
return newDate.format(DateTimeFormatter.ofPattern(datePattern));
} else if (date.matches(DDMYYYY_REGEX)) {
formatter = DateTimeFormatter.ofPattern("dd/M/yyyy");
newDate = LocalDate.parse(date, formatter);
return newDate.format(DateTimeFormatter.ofPattern("MMM dd, yyyy"));
return newDate.format(DateTimeFormatter.ofPattern(datePattern));
} else if (date.matches(DDMMYYYY_REGEX)) {
formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
newDate = LocalDate.parse(date, formatter);
return newDate.format(DateTimeFormatter.ofPattern("MMM dd, yyyy"));
return newDate.format(DateTimeFormatter.ofPattern(datePattern));
} else if (date.matches(DMYYYYHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("d/M/yyyy Hmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DMMYYYYHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("d/MM/yyyy Hmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DDMYYYYHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("dd/M/yyyy Hmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DDMMYYYYHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy Hmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DMYYYYHHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("d/M/yyyy HHmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DMMYYYYHHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("d/MM/yyyy HHmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DDMYYYYHHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("dd/M/yyyy HHmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else if (date.matches(DDMMYYYYHHMM_REGEX)) {
formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm");
newDateTime = LocalDateTime.parse(date, formatter);
return newDateTime.format(DateTimeFormatter.ofPattern("MMM dd H:mma, yyyy"));
return newDateTime.format(DateTimeFormatter.ofPattern(dateTimePattern));
} else {
return date;
}
}

private static LocalDateTime appendDate(LocalTime time) {
LocalDate localDate = LocalDate.now();
LocalTime localTime = LocalTime.of(time.getHour(), time.getMinute());
return LocalDateTime.of(localDate, localTime);
}

@Override
public String toString() {
return value;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/model/expense/Expense.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ public int hashCode() {
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getName())
.append(" Amount: ")
builder.append("\n")
.append(getName())
.append(" ")
.append(getAmount())
.append(" Date: ")
.append("\n")
.append(getDate())
.append(" Tags: ");
.append("\n");
getTags().forEach(builder::append);
return builder.toString();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/model/expense/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import org.apache.commons.lang3.StringUtils;

/**
* Represents the description of an expense in the expense list.
* Guarantees: immutable; is valid as declared in {@link #isValidName(String)}
Expand All @@ -28,7 +30,7 @@ public class Name {
public Name(String name) {
requireNonNull(name);
checkArgument(isValidName(name), MESSAGE_CONSTRAINTS);
fullName = name;
fullName = StringUtils.capitalize(name);
}

/**
Expand Down

0 comments on commit 03021f7

Please sign in to comment.