Skip to content

Commit

Permalink
Issue 31420 datetool (#31447)
Browse files Browse the repository at this point in the history
now the dateTool support toTimeStamp
  • Loading branch information
jdotcms authored Feb 26, 2025
1 parent 8c81f8b commit 1eb35bd
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@


import java.lang.reflect.Field;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -828,6 +829,81 @@ public Date toDate(String format, Object obj,
}
}

////////////

/**
* Converts an object to an instance of {@link Timestamp} using the
* format returned by {@link #getFormat()},the {@link Locale} returned
* by {@link #getLocale()}, and the {@link TimeZone} returned by
* {@link #getTimeZone()} if the object is not already an instance
* of Date, Calendar, or Long.
*
* @param obj the date to convert
* @return the object as a {@link Timestamp} or <code>null</code> if no
* conversion is possible
*/
public Timestamp toTimestamp(final Object obj)
{
return new Timestamp(toDate(obj).getTime());
}

/**
* Converts an object to an instance of {@link Timestamp} using the
* specified format,the {@link Locale} returned by
* {@link #getLocale()}, and the {@link TimeZone} returned by
* {@link #getTimeZone()} if the object is not already an instance
* of Date, Calendar, or Long.
*
* @param format - the format the date is in
* @param obj - the date to convert
* @return the object as a {@link Timestamp} or <code>null</code> if no
* conversion is possible
* @see #toDate(String format, Object obj, Locale locale)
*/
public Timestamp toTimestamp(final String format, final Object obj)
{
return new Timestamp(toDate(format, obj).getTime());
}

/**
* Converts an object to an instance of {@link Timestamp} using the
* specified format and {@link Locale} if the object is not already
* an instance of Date, Calendar, or Long.
*
* @param format - the format the date is in
* @param obj - the date to convert
* @param locale - the {@link Locale}
* @return the object as a {@link Timestamp} or <code>null</code> if no
* conversion is possible
* @see SimpleDateFormat#parse
*/
public Timestamp toTimestamp(final String format, final Object obj, final Locale locale)
{
return new Timestamp(toDate(format, obj, locale).getTime());
}

/**
* Converts an object to an instance of {@link Timestamp} using the
* specified format, {@link Locale}, and {@link TimeZone} if the
* object is not already an instance of Date, Calendar, or Long.
*
* @param format - the format the date is in
* @param obj - the date to convert
* @param locale - the {@link Locale}
* @param timezone - the {@link TimeZone}
* @return the object as a {@link Timestamp} or <code>null</code> if no
* conversion is possible
* @see #getDateFormat
* @see SimpleDateFormat#parse
*/
public Timestamp toTimestamp(final String format, final Object obj,
final Locale locale, final TimeZone timezone)
{
return new Timestamp(toDate(format, obj, locale, timezone).getTime());
}

///////////

/**
* Converts an object to an instance of {@link Calendar} using the
* locale returned by {@link #getLocale()} if necessary.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"info": {
"_postman_id": "04e24c3e-7d51-4e2b-be4a-e63094ab158d",
"name": "DateTool",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "781456"
},
"item": [
{
"name": "TestToTimeStamp",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code should be 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"var text = pm.response.text()",
"",
"pm.test(\"Right date\", function () {",
" pm.expect(text).to.be.eql('2025-02-06 00:00:00.0');",
"});",
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{jwt}}",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "$date.toTimestamp('yyyy-MM-dd','2025-02-06')",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/vtl/dynamic/",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"vtl",
"dynamic",
""
]
}
},
"response": []
}
]
}

0 comments on commit 1eb35bd

Please sign in to comment.