new DateUtils(todaysDate)
Creates a dateUtils object that offers convenience functions to get a date in a formatted way.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
todaysDate |
Date |
<optional> |
overwrites the current time with a fix date during the test run |
Example
var DateUtils = $.import("sap.hana.testtools.unit.util", "dateUtils").DateUtils;
var fixTodaysDate = new Date(2013, 8, 7, 11, 9, 7, 0); // valid month values:'0-11'
var dateUtilsForFixedDate = new DateUtils(fixTodaysDate);
Methods
-
getDateInTheFuture(daysToBeAdded) → {String}
-
Returns the date in the future. Adds some days to the current date.
Parameters:
Name Type Description daysToBeAdded
Integer Number of days in the past. Returns:
- Type
- String
Example
var DateUtils = $.import("sap.hana.testtools.unit.util", "dateUtils").DateUtils; var dateUtils = new DateUtils(); var tomorrow = dateUtils.getDateInTheFuture(1);
-
getDateInThePast(pastDays) → {String}
-
Returns the date in the past. Substracts some days from the current date.
Parameters:
Name Type Description pastDays
Integer Number of days in the past. Returns:
- Type
- String
Example
var DateUtils = $.import("sap.hana.testtools.unit.util", "dateUtils").DateUtils; var dateUtils = new DateUtils(); var yesterday = dateUtils.getDateInThePast(1);
-
getTodaysDate() → {String}
-
Returns the date of today.
Returns:
- Type
- String
Example
var DateUtils = $.import("sap.hana.testtools.unit.util", "dateUtils").DateUtils; var dateUtils = new DateUtils(); var today = dateUtils.getTodaysDate();
-
setFormat(dateFormat)
-
Sets the way the date should be formatted to overwrite the default "YYYYMMDD".
Parameters:
Name Type Description dateFormat
String takes one of the constants like DateUtils.YYYY_MM_DD or a string like "DD.MM.YYYY hh:mm:ss" where - 'YYYY' - full year
- 'MM' - month
- 'DD' - date
- 'hh' - hours
- 'mm' - minutes
- 'ss' - seconds
- 'SSS' - milliseconds
Example
var DateUtils = $.import("sap.hana.testtools.unit.util", "dateUtils").DateUtils; var dateUtils = new DateUtils(); dateUtils.setFormat(DateUtils.YYYY_MM_DD); //equivalent to setFormat("YYYY-MM-DD"); var formattedToday = dateUtils.getTodaysDate(); //e.g. "2014-07-16"
-
toString() → {String}
-
Returns the date of today.
Returns:
- Type
- String
Example
var DateUtils = $.import("sap.hana.testtools.unit.util", "dateUtils").DateUtils; var dateUtils = new DateUtils(); var today = "Today: " + dateUtils;