1. Home
  2. Docs
  3. UniREST Solution 3.5
  4. UniREST Client
  5. UniTools

UniTools

The UniTools class contains a collection of utility methods. All the exposed functionalities are under static methods, so they can be called directly from the class itself.

GetDate()

The GetDate() method convert a date into a string with the right format to be correctly recognized by the MySQL DateTime data-type. It has 2 overloads:

UniTools.GetDate(format = yyyy-MM-dd H:mm:ss);

This method overload just returns the current date and time in the international format as specified in the optional format parameter.

UniTools.GetDate(date, format = yyyy-MM-dd H:mm:ss);

This method overload returns the given date DateTime object converted in the international format as specified in the optional format parameter.

GetDateFromString

The GetDateFromString() method convert a string, containing a date and time, into a DateTime object.

UniTools.GetDateFromString(date, cultureInfo = 'en-US');

The date parameter must be a string containing a date and time definition. By default, the method expects the date and time are in English format (year-month-day hours:minutes:seconds). However, you can manage other data formats by setting the optional cultureInfo parameter to a different country code.

ConvertPercentage

The ConvertPercentage() is a utility method to generates a formatted string from a value which is a percentage from 0 to 1. This method converts this value into a number between 0 to 100, with a certain numbers of decimals, and add the % symbol.

UniTools.ConvertPercentage(value, decimalPlaces = 2);

For example, if you pass 0.2, the method will return 20%.

ConvertBytes

The ConvertBytes() is a utility method that converts a certain number of bytes in a more readable string of Kilobytes, Megabytes, Gigabytes and so on, with the given number of digits (optional, default = 1).

UniTools.ConvertBytes(value, decimalPlaces = 1);

Examples

Number of bytesReturned string
420420 bytes
26002.5 KB
12582911.2 MB