convert Bigdecimal to date
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
convert Bigdecimal to date
Hi
I receive JWT (Java token) in my APIS and it contain Expiration date as big decimal format (such as: 1691675508.431418)
I need to convent in to date & time format : yyyy mm dd HH MM SS Z
and use it in test case assertion
So I think i should use groovy script , but cant figure out how ?
OR if i can use any tools in ready api that do this conversion for me ?
I would be happy to share your experience on it with me
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can't think of any native functionality in ReadyAPI that'll do this.
You can use Java to convert bigDecimal dates to simpledate/datetime format.
A stackoverflow shows you how to perform the conversion. -->
BigDecimal bi = new BigDecimal("1096255084000");
double decimal_timestamp = bi.doubleValue();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(decimal_timestamp);
String date = formatter.format(calendar.getTime());
System.out.println(decimal_timestamp
I also found another option. -->
String value = bigDecimal.toString();
DateFormat format = new SimpleDateFormat("yyyyMMdd");
format.setLenient(false); // to prevent things like February 30th
Date date = format.parse(value);
We can of course tweak the above to do your conversion, HOWEVER, i'm unsure how to pick up a value from a JWT.
Think you might need a real expert like @KarelHusa o4 @ChrisAdams, etc.
Hope this gives you a start off point,
Cheers,
Rich
Cheers
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many Thanks Rich
I am not expert in scripting , but i try to use your suggestions as Groovy script in ReadyAPI
find two issue
1- Cant find your suggested methods in java.util.Calendar
2- When i try to convert big decimal value i receive form JWT token using formatter :
any value i receive it always convert to 1970-01-20 with different times ?!
BigDecimal BD1 = new BigDecimal("1669906025.870166");
BigDecimal BD2 = new BigDecimal("1670337568.956325");
BigDecimal BD3 = new BigDecimal("1670338168.956311");
double decimal_timestamp = BD1.doubleValue();
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS")
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
log.info 'formatter BD1 ' + formatter.format(BD1)
log.info 'formatter BD2 ' + formatter.format(BD2)
log.info 'formatter BD3 ' + formatter.format(BD3)
******* log
formatter BD1 20/01/1970 07:51:46.025
formatter BD2 20/01/1970 07:58:57.568
formatter BD3 20/01/1970 07:58:58.168
So do you have any suggestion ?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Curious, how the expiry date is going to be used?
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Rao
As part of JWT body It control validity time of Token Authentication.
So i need to control validity time & expiration of different token types.
In this case i need to parse token with such format i receive :
1669906025.870166
1670337568.956325
1670338168.956311
Regards
Behdad
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Behdad.
So, do you check the time each time a request is going to be send?
Does your response contain refresh_token?
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
U R wellcome
Of course
Refresh token is another endpoint of authentication package.
But as QA test , we need to have test cases to control and double check all details.
So in this case do you havre any suggestion to parse/convert timestamp values ?
