Static methods providing calculations.

package dstruct_common

 Methods

Get the number of bytes in a data size.

bytes(string $val) : integer
Static

Particularly useful when parsing parameters from php.ini. The method was converted from one from http://www.php.net/manual/en/function.ini-get.php. $val should be expressed as a float followed by 'k', 'm' or 'g' (not case sensitive) to denote the size 'scale'. Return is an integer, rounded where necessary. e.g. 1k returns 1024 1.2k returns 1229

Parameters

$val

string

Returns

integer

Calculates differences between dates.

dateDiff(string $interval, integer $number, integer $date) : integer
Static

WARNING: This method may well have bugs. It is better to use strtotime() or the Date object! It is likely to be deprecated in future. Interval can be one of: y = year, q = quarter, m = month, w = week, d = day, h = hour, m = minute, s = second. Combined values can be send to $interval such as 1q or 3y. In these instances, $number is ignored.

todo Handle incorrect parameters

Parameters

$interval

string

Intervals to be counted in or combined value (e.g. 1y, 2q)

$number

integer

Number of intervals to count

$date

integer

UTS date

Returns

integer

Calculates the Gross (eg inc VAT) value from the Net (eg ex VAT).

grossFromNet(float $net, float $rate, integer $resultflag, mixed $round) : mixed
Static

Parameters

$net

float

Net value

$rate

float

Percentage rate to use for calculations

$resultflag

integer

See class constants. Return Total, Difference or array with both

$round

mixed

Places to round to. Integer or False

Returns

mixedFloat or Array. See above.

Get the name of an array key.

keyName(array $a, integer $pos) : string
Static

Parameters

$a

array

Subject

$pos

integer

Key position

Returns

stringName of the key

Calculates the Net (eg ex VAT) value from the Gross (eg inc VAT).

netFromGross(float $gross, float $rate, integer $resultflag, mixed $round) : mixed
Static

If $diff is true, an array is returned with keys 'total' and 'diff'. 'total' is the gross value and 'diff' is the difference between net and gross.
If $diff is false, returns float

Parameters

$gross

float

Gross value

$rate

float

Percentage rate to use for calculations

$resultflag

integer

See class constants. Return Total, Difference or array with both

$round

mixed

Places to round to. Integer or False

Returns

mixedFloat or Array. See above.

Calculates rounding intuitively.

round(float $number, integer $precision, string $decsep) : float
Static

See https://svn0.conceptia.co.uk/web/wiki/PhpGotchas for more information Not sure where this function came from.

todo complete long description

Parameters

$number

float

Value to round

$precision

integer

Precision to round to (decimal places)

$decsep

string

Decimal Separator

Returns

float

Class constructor.

__construct() 

 Constants

 

Return the difference.

GROSSNET_DIFFERENCE : integer
 

Return the total.

GROSSNET_TOTAL : integer