You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 90 Next »

The class is used to conduct operations on SimpleDateTime objects, for example, instantiating objects.

You can also use this class to calculate, change formats of the date-time or convert between the formats.

SimpleDateTime(dateTime)


Instantiates a new SimpleDateTime object with the current or transferred date/time.

Parameter(s):

NameTypeMandatoryDefault Value
dateTimeStringN''


Example:

SimpleDateTime
const nowDateTime = new SimpleDateTime();
//
const registrationDateTime = new SimpleDateTime(record.registration_datetime);
//
const yearStartDateTime = new SimpleDateTime('2019-01-01 00:00:00');
//
const laborDayStart = new SimpleDateTime('2019-05-01');
//Info: 2019-05-01 00:00:00

addDays(days)


This method is used to change the number of days in the current SimpleDateTime object. The positive value of the parameter adds days to the object, the negative value diminishes the number of days.

The method changes the number of days according to the local date and time determined in the SimpleDateTime object.


Parameter(s):

NameTypeMandatoryDefault Value
daysintegerYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

addDays
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addDays(3);
ss.info(registrationDateTime.getValue());
//Info: 2019-01-04 08:12:10

addMonths(months)


This method is used to change the number of months in the current SimpleDateTime object. The positive value of the parameter adds months to the object, the negative value diminishes the number of months.

The method changes the number of months according to the local date and time determined in the SimpleDateTime object.


Parameter(s):

NameTypeMandatoryDefault Value
monthsIntegerYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

addMonths
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addMonths(-1);
ss.info(registrationDateTime.getValue());
//Info: 2018-12-01 08:12:10

addSeconds(seconds)


This method is used to change the number of seconds in the current SimpleDateTime object. The positive value of the parameter adds seconds to the object, the negative value diminishes the number of seconds.

The method changes the number of weeks according to the local date and time determined in the SimpleDateTime object.


Parameter(s):

NameTypeMandatoryDefault Value
secondsIntegerYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

addSeconds
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addSeconds(3600);
ss.info(registrationDateTime.getValue());
//Info: 2019-01-01 09:12:10

addWeeks(weeks)


This method is used to change the number of weeks in the current SimpleDateTime object. The positive value of the parameter adds weeks to the object, the negative value diminishes the number of weeks.

The method changes the number of weeks according to the local date and time determined in the SimpleDateTime object.


Parameter(s):

NameTypeMandatoryDefault Value
weeksIntegerYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

addWeeks
const registrationDateTime = new SimpleDateTime('2019-01-01 08:12:10');
registrationDateTime.addWeeks(1);
ss.info(registrationDateTime.getValue());
//Info: 2019-01-08 08:12:10

addYears(years)


This method is used to change the number of years in the current SimpleDateTime object. The positive value of the parameter adds years to the object, the negative value diminishes the number of years.

The method changes the number of years according to the local date and time determined in the SimpleDateTime object.


Parameter(s):

NameTypeMandatoryDefault Value
yearsIntegerYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

addYears
const contractStartDateTime = new SimpleDateTime('2019-01-01 00:00:00');
contractStartDateTime.addYears(1);
ss.info(contractStartDateTime.getValue());
//Info: 2020-01-01 00:00:00

after(dateTime)


This method allows to compare the date specified by the ‘dateTime‘ parameter with the current date. 

The method returns TRUE, if the current date is after the specified; otherwise returns FALSE.


Parameter(s):

NameTypeMandatoryDefault Value
dateTimeSimpleDateTime objectYN


Return:

TypeDescription
BooleanThe method returns TRUE if the current date is later than the date specified by the parameter; otherwise, returns FALSE.


Example:

after
const startDateTime = new SimpleDateTime('2018-01-01 07:58:35');
const endDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const isStartLaterThanEnd = startDateTime.after(endDateTime);
ss.info(isStartLaterThanEnd);
//Info: false

before(dateTime)


This method allows to compare the date specified by the ‘dateTime‘ parameter with the current date.

The method returns TRUE, if the current date is before the specified; otherwise returns false.


Parameter(s):

NameTypeMandatoryDefault Value
dateTimeSimpleDateTime objectYN


Return:

TypeDescription
BooleanThe method returns TRUE if the current date is earlier than the date specified by the parameter; otherwise, returns FALSE.


Example:

before
const startDateTime = new SimpleDateTime('2018-01-01 07:58:35');
const endDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const isStartBeforeEnd = startDateTime.before(endDateTime);
ss.info(isStartBeforeEnd);
//Info: true

compareTo(dateTime)


This method compares two date and time objects to determine whether they are equal and, if not, the method defines which goes after or before the other.


Parameter(s):

NameTypeMandatoryDefault Value
dateTimeSimpleDateTime objectYN


Return:

TypeDescription
0Dates are equal.
1Object's date is after the date specified in the parameter.
-1Object's date is before the date specified in the parameter.


Example:

compareTo
const firstDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const secondDateTime = new SimpleDateTime('2019-01-01 08:15:00');
const thirdDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(firstDateTime.compareTo(thirdDateTime));
ss.info(secondDateTime.compareTo(thirdDateTime));
ss.info(firstDateTime.compareTo(secondDateTime));
//Info: 0
//Info: 1
//Info: -1

equals(dateTime)


This method compares a datetime with an existing value to determine whether they are equal or not.


Parameter(s):

NameTypeMandatoryDefault Value
dateTimeSimpleDateTime object.YN


Return:

TypeDescription
BooleanThis method returns TRUE if the date are equal; otherwise, it returns FALSE.


Example:

equals
const firstDateTime = new SimpleDateTime('2018-01-01 08:00:00');
const secondDateTime = new SimpleDateTime('2018-01-01 08:15:00');
const thirdDateTime = new SimpleDateTime('2018-01-01 08:00:00');

ss.info(firstDateTime.equals(secondDateTime));
ss.info(thirdDateTime.equals(firstDateTime));
//Info: false
//Info: true

getDate()


This method returns the date saved by the SimpleDateTime object in the system time zone.


Return:

TypeDescription
StringThe date in the default timezone.


Example:

getDate
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDate());
//Info: 2019-01-01

getDayOfMonthLocalTime()


This method returns the day of the month saved by the SimpleDateTime object in the current user's time zone.


Return:

TypeDescription
IntegerThe day of the month value.


Example:

getDaysofMonthsLocalTime
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfMonthLocalTime());
//Info: 7

getDayOfMonthUTC()


This method returns the day of the month saved by the SimpleDateTime object in the UTC time zone.


Return:

TypeDescription
IntegerThe day of the month value.


Example:

getDaysofMonthsLocalTime
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfMonthUTC());
//Info: 7

getDayOfWeekLocalTime()


This method returns the day of the week saved by the SimpleDateTime object in the current user's time zone.


Return:

TypeDescription
StringThe day of week value. Possible values: 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' 


Example:

getDayOfWeekLocalTime
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfWeekLocalTime()); // Mon

getDayOfWeekUTC()


This method returns the day of the week saved by the SimpleDateTime object in the system time zone.


Return:

TypeDescription
StringThe day of week value.
Possible values: 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' 


Example:

getDayOfWeekUTC
const holidayDateTime = new SimpleDateTime('2019-01-07 08:00:00');
ss.info(holidayDateTime.getDayOfWeekUTC());
//Info: Mon

getDaysInMonthLocalTime()


This method returns the number of days in the month saved by the SimpleDateTime object in the current user's time zone.


Return:

TypeDescription
IntegerThe number of days value.


Example:

getDaysInMonthLocalTime
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDaysInMonthLocalTime());
//Info: 31

getDaysInMonthUTC()


This method returns the number of days in the month saved by the SimpleDateTime object in the system time zone.


Return:

TypeDescription
IntegerThe number of days value.


Example:

getDaysInMonthUTC
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDaysInMonthUTC());
//Info: 31

getDisplayValue()


This method returns the date and time value in the current user's display format and timezone.


Return:

TypeDescription
StringThe date and time value.


Example:

getDisplayValue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getDisplayValue());
//Info: 2019-01-01 11:00:00

getErrorMsg()


This method returns the error message if the SimpleDateTime object was incorrect.


Return:

TypeDescription
StringThe error message.


Example:

getErrorMsg
const startDateTime = new SimpleDateTime('2019-zz-01 08:00:00');
ss.error(startDateTime.getErrorMsg());
//Error: DateTimeZone::getOffset() expects parameter 1 to be DateTimeInterface, null given

getLocalDate()


This method returns the date saved by the SimpleDateTime object in the current user's time zone.


Return:

TypeDescription
StringThe date in the user's time zone.


Example:

getLocalDate
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getLocalDate());
//Info: 2019-01-01

getLocalTime()


This method returns the time saved in a SimpleDateTime object in the current user's time zone .


Return:

TypeDescription
SimpleDateTimeThe time in the user's time zone.


Example:

getLocalTime
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const time = startDateTime.getLocalTime();
ss.info( "My local time is " + time.getByFormat('h:i:s'));
//Info: My local time is 02:00:00

getMonthLocalTime()


This method returns the month saved by SimpleDateTime object in the current user's time zone.


Return:

TypeDescription
StringThe value of the month.


Example:

getMonthLocalTime
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getMonthLocalTime());
//Info: January

getMonthUTC()


This method returns the month saved by SimpleDateTime object in the system time zone.


Return:

TypeDescription
StringThe value of the month.


Example:

getMonthUTC
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getMonthUTC());
//Info: December

getNumericValue()


This method returns the Unix timestamp, which stores the amount of seconds since January 1, 1970, 00:00:00.


Return:

TypeDescription
IntegerThe Unix timestamp value.


Example:

getNumericValue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getNumericValue());
//Info: 1546329600

getTime()


This method returns a SimpleDateTime object that shows the piece of time of the SimpleDateTime object.


Return:

TypeDescription
SimpleDateTimeThe Unix duration stamp.


Example:

getTime
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
const time = startDateTime.getTime();
ss.info(time.getByFormat('h:i:s'));
//Info: 11:01:00

getValue()


This method returns the date and time value in the internal format.


Return:

TypeDescription
null | stringThe date and time value in the internal format.


Example:

getValue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
ss.info(startDateTime.getValue()); // 2019-01-01 08:00:00

getWeekOfYearLocalTime()


This method returns the week's number saved by the SimpleDateTime object in the current user's time zone.


Return:

TypeDescription
IntegerThe number of the current week.


Example:

getWeekOfYearLocalTime
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getWeekOfYearLocalTime());
//Info: 1

getWeekOfYearUTC()


This method returns the number of the week saved by the SimpleDateTime object in the system time zone.


Return:

TypeDescription
IntegerThe number of the current week.


Example:

getWeekOfYearUTC
const startDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(startDateTime.getWeekOfYearUTC());
//Info: 1

getYearLocalTime()


This method returns the year saved by the SimpleDateTime object in the current user's time zone.


Return:

TypeDescription
IntegerFour-digit year value.


Example:

getYearLocalTime
const holidayDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(holidayDateTime.getYearLocalTime());
//Info: 2020

getYearUTC()


This method returns the year saved by the SimpleDateTime object in the system time zone.


Return:

TypeDescription
IntegerFour-digit year value.


Example:

getYearUTC
const holidayDateTime = new SimpleDateTime('2019-12-31 23:45:00');
ss.info(holidayDateTime.getYearUTC()); 
//Info: 2019

isValid()


This method allows to determine if a specified value is a valid date and time.


Return:

TypeDescription
BooleanThe method returns TRUE if the value is a valid date and time; otherwise, it returns .


Example:

isValid
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
startDateTime.setValue("2011-aa-01 00:00:00");
ss.info(startDateTime.isValid());
//Info: false

setValue(dateTime)


This method sets the date and time of the SimpleDateTime object.


Parameter(s):

NameTypeMandatoryDefault Value
dateTimeA string in the UTC timezone and the internal format of YYYY-MM-DD hh:mm:ss.YN
dateTimeA SimpleDateTime object.YN
dateTimeA JavaScript Number. It sets the value of the object using the Number value as milliseconds past January 1, 1970, 00:00:00.YN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

setValue
const startDateTime = new SimpleDateTime('2019-01-01 08:00:00');
startDateTime.setValue('2020-01-01 12:00:00');
ss.info(startDateTime.getValue());
//Info: 2020-01-01 12:00:00

subtract(first, second)


This method returns the amount of time between two SimpleDateTime values. Also, it can subtract the amount of time from the current SimpleDateTime object.


Parameter(s):

NameTypeMandatoryDefault Value
first

SimpleDateTime Object

YN
first

SimpleTime Object

YN
first

Number (milliseconds)

YN
secondSimpleDateTime ObjectNNULL
secondSimpleTime ObjectNNULL
secondNumber (milliseconds)NNULL


Return:

Type
SimpleDuration object


Example:

subtract
const plannedDateTime = new SimpleDateTime(current.actual_end_datetime); // '2019-11-08 20:00:00'
const actualDateTime = new SimpleDateTime(current.planned_end_datetime); // '2019-11-08 20:06:28'

if (actualDateTime.after(plannedDateTime)) {
  const duraction = actualDateTime.subtract(plannedDateTime, actualDateTime); // 388
  if (duraction.getDurationSeconds() > 300) { // more than 5 minutes
    ss.eventQueue('notify.change_manager', current, current.assigned_user.getValue('manager'));
  }
}


Same example without using of the subtract:

const plannedDateTime = new SimpleDateTime(current.actual_end_datetime); // '2019-11-08 20:00:00'
const actualDateTime = new SimpleDateTime(current.planned_end_datetime); // '2019-11-08 20:06:28'
 
if (actualDateTime.after(plannedDateTime)) {
  const duraction = plannedDateTime.getNumericValue() - actualDateTime.getNumericValue(); // 388
  if (duraction > 300) { // more than 5 minutes
    ss.eventQueue('notify.change_manager', current, current.assigned_user.getValue('manager'));
  }
}

  • No labels