HMSfromFloatAMPM
A User Function for use with Oblivion Script Extender
Syntax:
(hh:mm:ss AM/PMstring) HMSfromFloatAMPM Valuefloat
Converts a value into a "hh:mm:ss AM/PM" formatted string.
Value is supposed to contain the hour + decimals, like the value returned by GameHour.
NotesEdit
- Value is normalized to 0-24 (e.g.: value 30,5 returns "06:30:00 AM", value -1 returns "11:00:00 PM").
Examples:Edit
Call HMSfromFloatAMPM 10,5 ; returns "10:30:00 AM" Call HMSfromFloatAMPM 17.25 ; returns "05:15:00 PM" Call HMSfromFloatAMPM GameHour ; returns the formatted game time
CodeEdit
scn HMSfromFloatAMPM ;--------------------------------------------------------------------- ; Converts an hour value into a formated string ;=================================== ; Input: a float containing the hour and decimals like the one returned by GameHour ; Returns: a string formatted as "hh:mm:ss AM/PM" ; ; Usage: Call HMSampmFromFloat GameHour ;--------------------------------------------------------------------- string_var sTime string_var sAMPM float value float vtime short ihour short imin short isec short i begin Function {value} ;=== Normalize to 0-24 === let i := value / 24 let vtime := value - i * 24 if vtime < 0 let vtime := vtime + 24 endif ;=== Format the Hour === set ihour to vtime set vtime to vtime - ihour ;=== conver to AM-PM === if ihour < 12 let sAMPM := " AM" else let sAMPM := " PM" endif let ihour := ihour % 12 if ihour == 0 let sTime := "12:" elseif ihour < 10 let sTime := "0" + $ihour + ":" else let sTime := $ihour + ":" endif ;=== Format Minutes === set vtime to vtime * .6 * 100 set imin to vtime if imin < 10 let sTime := sTime + "0" + $imin + ":" else let sTime := sTime + $imin + ":" endif ;=== Format Seconds === set vtime to vtime - imin set vtime to vtime * .6 * 100 set isec to vtime if vtime < 10 let sTime := sTime + "0" + $isec else let sTime := sTime + $isec endif SetFunctionValue sTime + sAMPM end