PowerTime Object  

Purpose

A PowerTime Object contains a date and time value, allowing easy calculations.  The internal representation emulates the Windows FILETIME structure as a quad-integer.  This value represents the number of 100-nanosecond intervals since January 1, 1601.   A nanosecond is one-billionth of a second.

You create a PowerTime object the same way you create other objects, but using a predefined internal class and a predefined internal interface.

LOCAL MyTime AS IPowerTime

LET MyTime = CLASS "PowerTime"

Once you have created a PowerTime object, you can manipulate it using the member methods.  The IPowerTime interface is DUAL -- member methods may be referenced using either Direct or Dispatch form.

Remarks

The Dispatch ID (DispID) for each member method is displayed within angle brackets.

An immediate use for the PowerTime Object is the built-in numeric equate %PB_COMPILETIME.  Each time you compile your program, this equate is filled with the current date and time of the compilation in PowerTime binary format.  You can use the PowerTIME Class to convert it to a text equivalent for use in your application.

LOCAL Built AS IPowerTime

LET Built = CLASS "PowerTime"

Built.FileTime = %PB_COMPILETIME

MSGBOX  Built.DateString

MSGBOX  Built.TimeString

POWERTIME Methods

AddDays <1> (ByVal Days&)

Adds the specified number of days to the value of this object.  You can subtract days by using a negative number.

AddHours <2> (ByVal Hours&)

Adds the specified number of hours to the value of this object.  You can subtract hours by using a negative number.

AddMinutes <3> (ByVal Minutes&)

Adds the specified number of minutes to the value of this object.  You can subtract minutes by using a negative number.

AddMonths <4> (ByVal Months&)

Adds the specified number of months to the value of this object.  You can subtract months by using a negative number.

AddMSeconds <5> (ByVal Milliseconds&)

Adds the specified number of milliseconds to the value of this object.  You can subtract milliseconds by using a negative number.

AddSeconds <6> (ByVal Seconds&)

Adds the specified number of seconds to the value of this object.  You can subtract seconds by using a negative number.

AddTicks <7> (ByVal Ticks&)

Adds the specified number of ticks to the value of this object.  You can subtract ticks by using a negative number.

AddYears <8> (ByVal Years&)

Adds the specified number of years to the value of this object.  You can subtract years by using a negative number.

DateDiff <11> (PowerTime, Sign&, Years&, Months&, Days&)

The date part of the internal PowerTime object is compared to the date part of the specified external PowerTime object.  The time-of-day part of each is ignored.  The difference is assigned to the parameter variables you provide.  Sign& is -1 if the internal value is smaller. Sign& is 0 if the values are equal.  Sign& is +1 if the internal value is larger.  The other parameters tell the difference as positive integer values.  If parameters are invalid, an appropriate error code is returned in OBJRESULT.

DateString <12> (OPT ByVal LCID&) AS String

Returns the Date component of the PowerTime object expressed as a string.  The date is formatted for the locale, based upon the LCID& parameter.  If LCID& is zero, or not given, the default LCID for the user is substituted.

DateStringLong <13> (OPT ByVal LCID&) AS WString

Returns the Date component of the PowerTime object, expressed as a string, with a full alphabetic month name.  The date is formatted for the locale, based upon the LCID& parameter.  If LCID& is zero, or not given, the default LCID for the user is substituted.

Day <15> () AS Long

Returns the Day component of the PowerTime object.  It is a numeric value in the range of 1-31.

DayOfWeek <16> () AS Long

Returns the Day-of-Week component of the PowerTime object. It is a numeric value in the range of 0-6 (representing Sunday through Saturday).

DayOfWeekString <17> (OPT ByVal LCID&) AS WString

Returns the Day-of-Week name of the PowerTime object, expressed as a string (Sunday, Monday...).  The day name is appropriate for the locale, based upon the LCID& parameter.  If LCID& is zero, or not given, the default LCID for the user is substituted.

DaysInMonth <18> () AS Long

Returns the number of days which comprise the month of the date of the PowerTime object.  This is a numeric value in the range of 28-31.

PROPERTY GET FileTime <20> () AS Quad

Returns a Quad-Integer value of the PowerTime object as a FileTime.

PROPERTY SET FileTime <20> (ByVal FileTime&&)

The FileTime Quad-Integer value specified by the parameter is assigned as the PowerTime object value.

Hour <21> () as Long

Returns the Hour component of the PowerTime object.  It is a numeric value in the range of 0-23.

IsLeapYear <22> () as Long

Returns true/false (-1/0) to tell if the PowerTime object year is a leap year.

Minute <23> () as Long

Returns the Minute component of the PowerTime object.  This is a numeric value in the range of 0-59.

Month <24> () as Long

Returns the Month component of the PowerTime object. This is a numeric value in the range of 1-12.

MonthString <25> () AS String

Returns the Month component of the PowerTime object, expressed as a string (January, February...).

MSecond <26> () as Long

Returns the millisecond component of the PowerTime object. This is a numeric value in the range of 0-999.

NewDate <27> (ByVal Year&, Opt ByVal Month&, Opt ByVal Day&)

The date component of the PowerTime object is assigned a new value based upon the specified parameters.  The time component is unchanged.  If parameters are invalid, an appropriate error code is returned in OBJRESULT.

NewTime <28> (ByVal Hour&, Opt ByVal Min&, Opt ByVal Sec&, Opt ByVal MSec&, Opt ByVal Tick&)

The time component of the PowerTime object is assigned a new value based upon the specified parameters.  The date component is unchanged.  If parameters are invalid, an appropriate error code is returned in OBJRESULT.

Now <29> ()

The current local date and time on this computer is assigned to this PowerTime object.

NowUTC <30> ()

The current Coordinated Universal date and time (UTC) is assigned to this PowerTime object.

Second <31> () as Long

Returns the Second component of the PowerTime object.  This is a numeric value in the range of 0-59.

Tick <32> () as Long

Returns the Tick component of the PowerTime object. This is a numeric value in the range of 0-999.

TimeDiff <33> (PowerTime, Sign&, Days&, OPT Hours&, OPT Minutes&, OPT Seconds&, OPT MSeconds&&, OPT Ticks&&)

The internal PowerTime object is compared to the specified external PowerTime object.  The difference is assigned to the parameter variables you provide.  Sign& is -1 if the internal value is smaller. Sign& is 0 if the values are equal.  Sign is +1 if the internal value is larger.  The other parameters tell the difference as positive integer values.  If you wish to return the time difference in units smaller than days, fill the unwanted parameters with BYVAL 0 and they will be ignored.  For example:

ThisObject.TimeDiff(ThatObject, Sign&, BYVAL 0, BYVAL 0, Minutes&)

In the above, if the difference was precisely one day, the value 1440 would be assigned to Minutes& (24 hours * 60 minutes).  If parameters are invalid, an appropriate error code is returned in OBJRESULT.

TimeString <34> () AS String

Returns the Time component of the PowerTime object expressed as a string.  The time is formatted as hh:mm AM/PM.

TimeString24 <35> () AS WString

Returns the Time component of the PowerTime object expressed as a string.  The time is formatted as hh:mm in 24-hour notation.

TimeStringFull <36> () AS WString

Returns the Time component of the PowerTime object expressed as a string.  The time is formatted as hh:mm:ss.mmm in 24-hour notation.

Today <38> ()

The current local date on this computer is assigned to this PowerTime object.  This is suitable for applications that work with dates only.

ToLocalTime <39> ()

The PowerTime object is converted to local time.  It is assumed that the previous value was in Coordinated Universal Time (UTC).

ToUTC <40> ()

The PowerTime object is converted to Coordinated Universal Time (UTC).  It is assumed that previous value was in local time.

Year <42> () as Long

Returns the Year component of the PowerTime object as a numeric value.

See also

DATE$, DAYNAME$, MONTHNAME$, TIME$