-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure assignment date is in ISO8601 format (FF-1933) (#46)
- Loading branch information
1 parent
b8f086b
commit edc28d8
Showing
5 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ plugins { | |
} | ||
|
||
group = "cloud.eppo" | ||
version = "1.0.7" | ||
version = "1.0.8" | ||
|
||
android { | ||
compileSdk 33 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package cloud.eppo.android; | ||
|
||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
import cloud.eppo.android.util.Utils; | ||
|
||
public class UtilsTest { | ||
|
||
@Test | ||
public void testGetISODate() { | ||
String isoDate = Utils.getISODate(new Date()); | ||
assertNotNull("ISO date should not be null", isoDate); | ||
|
||
// Verify the format | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); | ||
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
try { | ||
Date date = dateFormat.parse(isoDate); | ||
assertNotNull("Parsed date should not be null", date); | ||
|
||
// Optionally, verify the date is not too far from the current time | ||
long currentTime = System.currentTimeMillis(); | ||
long parsedTime = date.getTime(); | ||
assertTrue("The parsed date should be within a reasonable range of the current time", | ||
Math.abs(currentTime - parsedTime) < 10000); // for example, within 10 seconds | ||
} catch (ParseException e) { | ||
fail("Parsing the ISO date failed: " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetCurrentDateISOInDifferentLocale() { | ||
// Arrange | ||
Locale defaultLocale = Locale.getDefault(); | ||
try { | ||
// Set locale to Arabic | ||
Locale.setDefault(new Locale("ar")); | ||
String isoDate = Utils.getISODate(new Date()); | ||
|
||
// Act | ||
// Check if the date is in the correct ISO 8601 format | ||
// This is a simple regex check to see if the string follows the | ||
// YYYY-MM-DDTHH:MM:SSZ pattern | ||
boolean isISO8601 = isoDate.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z"); | ||
|
||
// Assert | ||
assertTrue("Date should be in ISO 8601 format", isISO8601); | ||
|
||
} catch (Exception e) { | ||
fail("Test failed with exception: " + e.getMessage()); | ||
} finally { | ||
// Reset locale back to original | ||
Locale.setDefault(defaultLocale); | ||
} | ||
} | ||
} |