Skip to content
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

Issue 31420 datetool #31447

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": []
}
]
}
Loading