-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure assignment date is in ISO8601 format (FF-1933) #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,9 @@ | |
import java.math.BigInteger; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.TimeZone; | ||
import java.util.Locale; | ||
|
||
import cloud.eppo.android.dto.ShardRange; | ||
|
||
|
@@ -50,10 +49,9 @@ public static void validateNotEmptyOrNull(String input, String errorMessage) { | |
} | ||
|
||
public static String getISODate(Date date) { | ||
TimeZone tz = TimeZone.getTimeZone("UTC"); | ||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); | ||
df.setTimeZone(tz); | ||
return df.format(date); | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
dateFormat.setTimeZone(java.util.TimeZone.getTimeZone("UTC")); | ||
return dateFormat.format(date); | ||
} | ||
|
||
public static SharedPreferences getSharedPrefs(Context context) { | ||
|
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙌 |
||
|
||
@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()); | ||
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ran this test without the fix:
|
||
|
||
// 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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice