Go to day home page Methods are initially capitalised. Properties are initially lower case. 'private' items are initially underscored.

DAYo.js

D/a/y object

DAYo

23constructorInitialiser
ForceFlag
Overall constructor
How the various initialisations are delegated
Constructor
+--_Reset
+--From
+--FromJulian
+--From32Bits
+--FromTimestamp
+--FromString
| +--FromYMDHMS
| +--FromText
+--FromDate
+--FromDAYo
+--FromArray
_Sanitize
1709AddDaysNoDays add (-ve = subtract) a given number of days from a specific CAL date
NK,EOT,BOT return themselves
Anything else returns NV
AR1 When adding days alone to a date:
Count according to the real calendar.
AR2 Use method a.
*** If AR2b is required use Tinterval method *** 'D'
1750AddMonthsNoMonths add ( -ve = subtract ) specified number of months
AR3:
When adding months alone to a date:
Convert the days part of the date into fractions of that month.
Then add the months, carrying base 12 as required.
Now convert the fraction back into days according
to the actual length of the new month.
May throw error if trying to add months to just a year but this
will be ignored if NoMonths is a multiple of 12
  • Can't add month to bare year in DAYo.AddMonths()
  • Can't add month to day-only float in DAYo.AddMonths()
1799AddYearsNoYears add ( -ve = subtract ) specified number of years
1587AfterAday compares the logical values of the dates.
Returns true if THIS is AFTER before ARGUMENT
See Before()
1303AsDays Convert an interval into days
Result may be fractional and negative
1552BeforeAday compares the logical values of the dates.
Returns true if THIS is DEFINITELY before ARGUMENT
Note there are many cases where this test doesn't
make sense or where the data cannot possibly be
interpreted. All of these will return false without
any error being raised. Therefore it is up to
the programmer to avoid propagating spurious FALSEs
by suitably guarding before calling.
922BoT Construct DAYo for Beginning of time
1504CalendarType if this is a CAL then tell what type
0 .. fully specified DAYu.CALTYPE_YMD 000
1 .. no day DAYu.CALTYPE_YMX 001
3 .. just year DAYu.CALTYPE_YXX 011
7 .. not calendar DAYu.CALTYPE_ERR 111
These funny values are because we use them in various representations to mask
components we don't use. A 1 bit signifies unused
835ClearWWWS Clear .whatWentWrongStr
1633ContainsAday Return true if this date is the same as or encompasses
the argument. This must have the same or lower precision
than the argument.
Possible combinations for sensible testing
------------------------------------------
CAL
y m d - y m d
y m 0 - y m d
y 0 0 - y m d, y m 0
FLO
0 m 0 - 0 m d
Unsuitable values return false not an exception
1901DateToStringTemplate return a string representation of a CAL or FLO
The format string is a sequence of two-character tokens
that describe the elements to be included in the output
These may be interleaved with literal characters.
The Day(number) and Month elements will normally
automatically be exchanged to match the DM_ORDER parameter
in the appendix. (can be disabled with the -S flag)
CALENDAR DATE FORMATTING CODES
------------------------------
y1 ... year without any leading zeroes
y2 ... 2-digit year
y4 ... 4-digit year
m1 ... 1 or 2-digit month number
m2 ... 2-digit month number
M2 ... Month name tiny
M3 ... Month name short
M4 ... Month name long
d1 ... 1 or 2-digit day number
d2 ... 2-digit day number
D2 ... Day name tiny
D3 ... Day name short
D4 ... Day name long
BC ... BC indicator
FLAGS
------------------------------
-T ... Don't use 'Today'
-E ... Add extended NV and NVI reasons
-S ... Disable effect of DM_ORDER
1261Day return day element 0 implies not set
1344DayOfWeek Day of week
No date-day returns 0. Monday ... Sunday returns 1 ... 7
1856DaysDifferenceAday How many days difference
1862DumpStr Return string version of internal state for debugging
924EoT Construct DAYo for End of time
1156FirstDay return first specific day
1524FloatType if this is floating then tell what type
6 .. Floating day DAYu.FLOTYPE_XXD 110
5 .. Floating month DAYu.FLOTYPE_XMX 101
4 .. Floating month-day DAYu.FLOTYPE_XMD 100
0 .. not floating DAYu.FLOTYPE_ERR 000
These funny values are because we use them in various representations to mask
components we don't use. A 1 bit signifies unused
1248FractionOfMonth How far through month are we?
Might throw error if year needed for February and not given
Only applicable to CALs of form y+m+d and m+d
68FromInitialiser
ForceFlag
Try to load from given Initialiser
Initialiser is a string, number, Date, Dayo or an array
Sometimes a value could be interpreted in more than one way so
ForceFlag may be used to clarify how the input is to be interpreted
- String See documentation for details.
OPTIONALLY USE ForceFlag as follows:
None Default Guess from pattern matching
DAYu.forceYMD ... Ignore H:M:S elements of Unix timestamp
DAYu.forceYMDHMS ... uses H:M:S elements of Unix timestamp
- Number --> From32Bits()
OPTIONALLY USE ForceFlag as follows
None Default ... assume input is a 32-bit number
DAYu.force32Bits ... Force 32 bit conversion
DAYu.forceJulian ... Julian day
DAYu.forceTimeStamp ... UNIX timestamp
- undefined,false and null ==> NV and no error
- DAYo object
- Date object
Same ForceFlag options as string
- Array of 'Signature,Sign,y,m,d,Errorcode' (Throws error string if any duff parameters)
Return false if the Initialiser was readable but gave strange values
  • Unsuitable object passed to DAYo constructor
  • Unsuitable value passed to DAYo constructor
797From32BitsUnsignedInt Read native 32-bit format
Sets DAY from number
bits 31 - 29 Signature
bits 28 Sign 0:-ve 1:+ve
bits 27 - 16 Year 0 ... 4095
bits 15 - 12 Month 1:Jan ... 12:Dec 0 is legal
bits 11 - 7 Day of month 1 ... 31 0 is legal
bits 6 - 3 Day of week (Fully specified) 1:Mon ... 7:Sun 0:Undefined
Not valid reason code (NV) See table 7
bit 3 Not used
bit 2 Valid flag 1:Is validated
bit 1 Fully specified 1:Is fully specified
bit 0 Interval 1:Is interval
Doesn't sanitize
144FromArrayAy Ay is of the form 'Signature,Sign,Y,M,D,Error code'
Does not sanitize
129FromDAYoDayObj Clone a DAY object
190FromDateJsDate
UseTimeBits
Use a Javascript Date object to populate ourselves
JsDate is a Javascript Date object
UseTimeBits is a boolean flag to tell if the HMS
part is to be used for rich dates. This would be
false or missing for fully specified dates
(ie. where Y,M and D are all valid).
Note that if H,Mins,S are all 0 it is automatically
treated as a simple YMD case.
  • FromDate needs a Javascript Date object
159FromJulianJulian Set ourselves from a Julian day number
Does not sanitize
111FromStringStr
ForceFlag
Str is either some sort of human input like '23 May 2014'
or YYYY-MM-DD or YYYY-MM-DD HH:MM:SS
The optional ForceFlag can be used to use or ignore the HH:MM:SS part of the timestamp
If the HMS part is present and ForceFlag is DAYu.strYMDHMS then use the overloaded/encoded
time elements to create a rich DAYo
257FromTextStr Read an ordinary human style text input
  • NVI'){throw "FromText() doesn't take intervals
176FromTimestampUnixMilliseconds
UseTimeBits
UnixMilliseconds is a standard UNIX timestamp
Optional UseTimeBits is for when you can't use native 32-bit format
Really a wrapper for .FromDate()
527FromYMDHMSStr
UseTimeBits

  • FromYMDHMS() expected HMS part missing
838GetErrorCode what is the numerical value of the error
833GetWWWS Get .whatWentWrongStr
1010HasDay Return true if the day component is specified
1007HasMonth Return true if the month component is specified
1013HasYear Return true if the year component is specified
1016IsBC Return true if the sign component is negative
948IsBoT Test for BoT signature
983IsCalendar Is this a calendar day of the form Y or YM or YMD
951IsEoT Test for EoT signature
978IsErrorFree True if there is no error reported
969IsFloating Test for a FLO signature
956IsGiven Test for a signature indicating a workable date
ie. NK, BoT, Cal or EoT
994IsGoodCalendarMonthRequired
DayRequired
Is it error-free and a calendar day with specified precision
MonthRequired and DayRequired are boolean flags
960IsKnown Test for signature indicating a 'known' date.
ie. BoT, Cal or EoT
945IsNotKnown Test for NK signature
973IsRealPeriod Test for a real date which could be Y or YM
ie. Day component is missing
748IsSameValueDAYobj
StrictFlag
============================================
See if two DAYs have the same value
If StrictFlag is truthy then errorCodes must match as well.
============================================
964IsSpecific Is this a Cal that referrs to a specified day.
ie. Day, month and year components are all specified
1025IsToday Return true if this is today
937IsValid Does DAYo have a valid signature
This does not mean free from errors
See IsErrorFree() and IsGoodCalendar()
942IsValidDate Test for a valid DAYo signature
This does not mean free from errors
See IsErrorFree() and IsGoodCalendar()
1330Julian Julian() Return Julian day number
* VERY IMPORTANT FUNCTION *
Returns iNV if not a fully specified date
1159LastDay return last specific day
1170Middle Middle date of a range
1272Month return month element 0 implies not set
1850MonthsDifferenceAday How many months difference
926NK Construct DAYo for Not known
928NV Construct DAYo for Not Valid
1165Next return next Same sort of period
1162Previous return previous Same sort of period
769SetYearYear Set Year and deal with negative values
1295Signature returns signature (integer)
1484SortsBeforeAday Does this DAYo sort before the DAYo in the argument
(Intervals sort by magnitude, everything else by 32-bit representation.)
1369To32Bits To32Bits()
Returns an unsigned number
bits 31 - 29 Signature
bits 28 Sign 0:-ve 1:+ve
bits 27 - 16 Year 0 ... 4095
bits 15 - 12 Month 1:Jan ... 12:Dec 0 is legal
bits 11 - 7 Day of month 1 ... 31 0 is legal
bits 6 - 3 Day of week (Fully specified) 1:Mon ... 7:Sun 0:Undefined
Not valid reason code (NV) See table 7
bit 3 Not used
bit 2 Valid flag 1:Is validated
bit 1 Fully specified 1:Is fully specified
bit 0 Interval 1:Is interval
1458ToDate return a fully encoded Javascript Date
H, m and s are encoded
1205ToStringArg1
Arg2
ToString('Template','ExtendErrorCodeFlag')
Default string representation.
• Template (string) : See .DateToString() for template details and options
• ExtendErrorCodeFlag (boolean) : Missing/False->Number code True->String messages
1400ToYmdhmsResultType ToYmdhms(ResultType)
Depending on the ResultType argument this can return
'ARRAY' an array encoded the form 'y,m,d,h,m,s'
'DATE' a javascript Date object with h,m,s encoded
'YMDHMS' a string formatted as yyyy-mm-dd hh:mm:ss
'YMDTHMSZ' a string formatted as yyyy-mm-ddThh:mm:ss.000Z
'STAMP' Unixy timestamp version of DATE (milliseconds since January 1, 1970, 00:00:00 UTC -ve for prior)
  • ToYmdhms() is unable to make a date. Original=
  • ToYmdhms has unknown ResultType("+ResultType+')
920Today Construct DAYo for Today
1282Year returns a signed year number or 0 if not set
1843YearsDifferenceAday How many years difference
1317_FloatingMetric Internal function that returns a simple
metric 'day count' 32 * days + months
Only applicable to floats
2053_LimitCharsNum
Padding
Turn a string into a number with 0,2 or 4 zeros padding
Padding should be 0, 2 or 4
731_MatchesArrayOfInnerValues _Matches
Tests internal structure against supplied array
'Signature,Sign,y,m,d,errorCode'
1042_RangeEndBegOrEnd
  • Improper argument for _RangeEnd()
  • Improper signature for _RangeEnd()
  • Missing year for _RangeEnd()
32_Reset Reset all internal values
628_Sanitize _Sanitize
Private method to ensure internal values are safe
If any errors then sanitize them and set signature to NV
Return false if any errors found
Tell error to .whatWentWrongStr
472_SetCalHelperY
M
D
We've got a d,m and y to process to finish
446_SetFloatHelperM
D
We've got a float, so finish it off.
The patterns are
(0,day),(month,0),(month,day)
884_SetFloatsPartialMask Zero any of the Y M D values in a Flo according to
The three-bit PartialMask
If PartialMask is invalid or not a Flo then return false
Typical use is when masking during an input conversion
Return false if an issue
518_SetNvHelperCode
Desc
We've got an error so set this to not valid
Code is a DAYu error code
Desc is an optional txt message to go into what went wrong (See ._WWWS)
848_SetPartialsPartialMask Zero any of the Y M D values in a Cal according to
The three-bit PartialMask
If PartialMask is invalid or not a Cal then return false
Typical use is when masking during an inout conversion
Return false if an issue
831_SetWWWSNewErrorStr Add error message to .whatWentWrongStr
NewErrorStr should be of the form: 'current routine' message
1093_StepBegOrEnd
  • Improper signature for _Step()
  • Improper argument for _Step()

DAYu.js

Utilities and constants
~~~~~~~~~~~~~~~~~~~~~~~
DAYu is a singleton, more for namespacing than anything

DAYu

42BADFROMFORMAT1, weird input to a .From...() method
43BADFROMVALUE2, some value to a .From...() method is unsuitable
22BoT5, beginning of time
106CALTYPE_ERR7, types of calendar dates
107CALTYPE_YMD0, fully specified ->>PRECISION_DAY->>3
108CALTYPE_YMX1, no day (M+Y) ->>PRECISION_MONTH->>2
109CALTYPE_YXX3, just year ->>PRECISION_YEAR-->1
79CONV_STATUS_INVALIDEXT1, Invalid extension found in t/stamp or date
80CONV_STATUS_NOT_FULL_DATE2, Conversion failure of some sort
23Cal6, Calendar date
675Convert2to4DigitYearYear,BlockFlag Given the supplied two digit year
convert it into a 4 digit year using the rules given
by the TWO_DIGIT_FIX setting.
0 = Disallow
20 = convert yy -> 20yy
50 = convert yy so that it lies between 50 years ago and 50 years ahead
If the argument <0 or TWO_DIGIT_FIX = 0 then return 0
If the argument is already 4 digits then leave it alone
Year can be a string (preferable) as this helps weed things like 0067 which is 0067 not 2067 etc
Optional BlockFlag returns the number without any conversion
To call from inside DAYo use (this.sign==DAYu.neg)
returns 0 if fail/disallow
127DAYSINMONTH30.4375, 365.25 / 12
54DFS_STATUS_ALPHANOTUNDERSTOOD3, alpha isn't shortcut or month name
57DFS_STATUS_CANTDECODEDDMMYY5, 2,4,6 or 8 digits only
49DFS_STATUS_EMPTYSTRING1, all whitespace
53DFS_STATUS_MORETHANONEALPHA2, only 1 alpha token allowed
52DFS_STATUS_NOTOKENS2, no alpha numerics in string
48DFS_STATUS_OK0,
50DFS_STATUS_TOOLONG1, sanity limit of 40 characters (far more than needed)
51DFS_STATUS_TOOMANYTOKENS2, max 6 tokens (far more than needed)
59DFS_STATUS_UNKNOWNERROR7, Sanitize failure
58DFS_STATUS_UNSUITABLENUMBER6, unsuitable numeric value somewhere
55DFS_STATUS_YEARMISSINGORBAD4, missing or bad year
56DFS_STATUS_YEARNOT2OR4DIGITS4 , year must be yy or yyyy
347DayCountToYmdIntArrayDayCount DayCount is a number of days (Not necessarily an integer)
Return an array of 'Y,M,D' after applying the necessary conversions
Uses the fractional conversion factor DAYu.DAYSINMONTH
332DayOfMonthToFractionY,M,D How far through the month is this d/m/y?
Can throw error if year is missing
415DaysDifferenceAday1,Aday2 Number of days between date1 and Date2
Example : If D1 is '1 Jan 2001' and D2 is '2 Jan 2001' then result is +1
Uses Julian day subtraction
307DaysInGivenMonthM,Y How many days in given month?
If m is 2 then use (optional) y to tell us if it is a leap year
If y is 0 then it is not a leap year
Illegal m argument or m=2 and y=undefined throws an error
572EarliestFinishArrayOfCals,IgnoreUnsuitable What is the earliest finish of these dates?
Only Cals are suitable values for the array.
NVI,INT,NV,FLO will throw an exception
NK,BoT,EoT will NORMALLY throw an excepton
UNLESS the optional 2nd arg is set true when NK->NK,EoT->EoT and BoT ignored
Zero-length array throws an exception
536EarliestStartArrayOfCals,IgnoreUnsuitable What is the earliest start date of these dates?
Only Cals are suitable values for the array.
NVI,INT,NV,FLO will throw an exception
NK,BoT,EoT will NORMALLY throw an excepton
UNLESS the optional 2nd arg is set true when NK->NK,BoT->BoT and EoT ignored
Zero-length array throws an exception
24EoT7, End of time
20FLO3, floating date
103FLOTYPE_ERR2, error
102FLOTYPE_XMD4, month and day only
101FLOTYPE_XMX5, month only
100FLOTYPE_XXD6, types of floating date
76FTS_STATUS_INVALIDSIG1, Error codes for FromTimestamp & date
339FractionToDayOfMonthY,M,Fraction Inverse of dayOfMonthToFraction()
272GetDefaultYear return the default year
Use IMPLIED_YEAR to tell us what to do
return iNV if missing years are not allowed
IMPLIED_YEAR ... Return
0 ........ iNV Do not allow inputs that miss out year part. Return iNV
-1 ........ yyyy Use the current year
-2 ........ 0 Allow floating date input
nnnn ........ nnnn Use the specified year
Possible returns are iNV,0,yyyy
66IFS_STATUS_BADLENGTH1, too short or too long
68IFS_STATUS_NOTOKENS2, Must have at least one part
65IFS_STATUS_OK0,
71IFS_STATUS_SIGNMISPLACED5, + or - other than at start
69IFS_STATUS_SIGNMISSING3, must start with + or -
67IFS_STATUS_TOOMANYTOKENS2, Can only have three parts
70IFS_STATUS_UNKNOWNUNIT4, suffix not recognised
72IFS_STATUS_UNSUITABLENUMBER6, unsuitable numeric value somewhere
18INT1, Interval
115INTTYPE_D3, precise to day (same as PRECISION_DAY)
112INTTYPE_DDD0, types of interval precision
114INTTYPE_M2, precise to month (same as PRECISION_MONTH)
116INTTYPE_X-1, error
113INTTYPE_Y1, precise to year (same as PRECISION_YEAR)
289IsLeapYearY Is a given year a leap year?
248JulianToCalJulian
226JulianToYMDJulian Split Julian day number into array 'of Y,M,D'
It may throw an exception through an unsuitable input
(2436064 = 13/08/57)
* SEE ALSO JulianToCal() *
560LatestFinishArrayOfCals,IgnoreUnsuitable What is the latest finish of these dates?
Only Cals are suitable values for the array.
NVI,INT,NV,FLO will throw an exception
NK,BoT,EoT will NORMALLY throw an excepton
UNLESS the optional 2nd arg is set true when NK->NK,EoT->EoT and BoT ignored
Zero-length array throws an exception
548LatestStartArrayOfCals,IgnoreUnsuitable What is the latest start date of these dates?
Only Cals are suitable values for the array.
NVI,INT,NV,FLO will throw an exception
NK,BoT,EoT will NORMALLY throw an excepton
UNLESS the optional 2nd arg is set true when NK->NK,BoT->BoT and EoT ignored
Zero-length array throws an exception
645MonthOnlyAday Return a DAYo with just the month component
448MonthsDifferenceAday1,Aday2 calculate (or approximate if days are involved)
the number of months difference.
(Date2 - Date1)
Arguments must have the same pattern of y/m/d components
and be CAL or FLO.
Cal y m d, y m 0 or y 0 0
FLO 0 0 d, 0 m 0 or 0 m d
21NK4, date not known
19NV2, Not a date value
136NVD_INT_MULTINEGATIVE1, Not valid details
---day---
---date---
---int---
17NVI0, Invalid interval
83NVR_FUNCTION_FAILURE7, Not valid reasons
84NVR_NOT_CONCURRENT8, '@' change to 1..7
122PRECISION_DAY3, fully specified
119PRECISION_ERR-1, types of precision NB The greater the value the more precise
121PRECISION_MONTH2, only to months
120PRECISION_YEAR1, only to years
130SECONDSPERDAY864000, eg (J - UNIXDAYSTOJULIAN) * 86400 -> U
151SigToStrSig Signature code to three character string
161SignToStrSign Sign to three character string
393SortsBeforeDay1,Day2 Compare two DAYo objects
If both are intervals then compare magnitude
otherwise compare on 32 bit representation
Return -1 d1 < d2
0 d1 == d2
+1 d1 > d2
(Note this is SIMILAR but not identical to DAYo.SortsBefore()
which conflates == and > into false.)
128UNIXDAYSTOJULIAN2440587, Number to add to Unix day number to get Julian day number
141UNIX_BOT-2147540400, 13 Dec 1901 05:00:00
142UNIX_EOT2147410800, 18 Jan 2038 07:00:00
140UNIX_NK-2147544000, 13 Dec 1901 04:00:00
139UNIX_NV-2147551200, special values for unix timestamps
61UNKNOWNERROR7, Sanitize failure
176YMDToJulianYr,Mo,Dy Create Julian day number from Year, month and day
Year can be +ve or negative
Warning: No sanity checking of arguments is done
491YearsDifferenceAday1,Aday2 Practically the same as MonthsDifference / 12 except
- unsuitable args returns iNV
- where CAL pattern is y 0 0 the calculation is simple subtraction.
713_Diva,b Utility integer division function
580_EarliestLatestAnyAllCaller,ArrayOfCals,IgnoreUnsuitable Internal servicing method for Earliest/Latest Any/All
Caller is two character code eg EF for EarliestFinish
739_IsAlphaStr returns true if Str is all alpha
744_IsNumericStr returns true if Str is all numbers
724_PadIntLeftPadChr,Num,Width,Zero Utility pad-right for integer
LeftPadChr is typically 0 or space
Num is numeric value
Width is total width (Grows by 1 if Num is -ve)
Zero is an optional substitute character for 0
374_StepYearYear,Increment Step year up or down but trap year 0
38badNumber6, FromJulian()
36badSetObject2, DAYo.Set() given inappropriate object
35badSetSignature1, DAYo.Set() given inapropriate signature
31canNeverHappen001-1, Dayo.Set()
95force32Bits103,
94forceJulian101,
96forceYMD104,
97forceYMDHMS105,
91iNV-9999999, integer not valid return value iNV
27neg0, sign negative
32noError0,
28pos1, sign positive
37unsuitableRange3, DAYo.Middle() on inapropriate object
14version"Built on {{BUILDDATE}}", placeholder modified by build-tools

DAYc.js

Internationalisation and parameters configuration
Singleton

DAYc

150AllowDayOnlyIntervalsNewValBool Do we allow INTs to be created with more than 31 days eg +0y 0m 66d
135AllowExcessDaysInMonthNewValBool Get/Set true if we allow silent coercing of slightly
too many days in month to end of month
192BCIndicator String used to indicate negative years
@@@ needs to rewritten as get/set
263BuildCommonTerms We need to look up shortcuts quite often for inputs so build
A list of shortcuts (eg B for BoT) and other terms such as Beg-of-time
247BuildInputHacks Create a lookup dictionary to allow some inputs to be converted
to other (more acceptable ones)
283BuildMonthLookups We're quite likely going to need to look-up month names
As with Common Terms we need a shortest version and a full version
for different ways of matching
431DumpCfg Diagnostic for useful parameters usually pertaining to input strings
419ExtendedErrorStrSig,Err return error string if applicable
460INITIAL_DATA[ Default, built-in en-gb settings
164ImpliedYearNewValInt Get/Set numeric value of IMPLIED_YEAR
Allowable inputs are 0,-1,-2 or a year > 999
453InYearLimitsYear Check to ensure the year given is within current limits.
Only applies to INT and Cal
61InitialiseOptionalAppendixData Load the appendix file with the UI settings
Must be done early on
Returns false if there is an error
OptionalAppendixData is text in appendix format
@@@ We need another method such as GetAppendix(appx-name) as a wrapper
That will be file getting and asynch :(
312InterpretStringInpStr Interpret string
Return '' or 0 for not understood
Return 'BoT','EoT','NK','NV','TODAY','NVI' if found
Return month number
121IsDmyOrderNewValBool Get/Set true if we are working in a d-m-y environment
Always returns boolean'
Only changed if NewValBool is of type boolean
7KVnew Dict(),
102LookupStr,Num Lookup a key
The args may be just a string or a string and number eg ('BoT',3)
410MonthNameMonNum,Version Convert month number into a name
MonNum 1..12
Version 1..4 (2 is 3 characters length)
365SearchMonthsInpStr Search month names to return a numeric equivilent eg Fe -> 2
Return a numeric equivilent or 0 if not found
330SearchShortcutsPossibleShortcutStr Search shortcuts to return a string code eg "BoT"
Return null string for not found
347SearchTermsPossibleTerm Look to see if PossibleTerm might be start of a standard term
For example PT=Be ST=Beg-of-Time -> "BoT"
returns key string or null string
110SetKeyValueKey,Value Temporaraly (session) set a K-V pair in the configuration
Preferably use one of the direct convenience methods
178TwoDigitFixNewValInt Get/Set numeric value of TWO_DIGIT_FIX
Allowable inputs are 0,20,50
203_ExtractAppxSettingsAppxFileData,FirstLoad (private) Read appendix file data. Sets .error to null string if OK
85_Rebuild
9appendix"en-gb.dax", actual file name
8error'', eg load issue such as badly formatted file
12force2or4DigitYearsfalse, if true then years input MUST be in the form yy or yyyy
10i18n"i18n", path (no trailing slash) to appendix
49inputHacksnew Dict(), AltStr -> NormalStr (all u/case)
11intervalRegEx/^([-\+])((\D*(\d+)([ymd])){1,3})/i, This is an interval DETECTOR. ie. All must match
48months1new Dict(), July ->4
47months32new Dict(), Jy ->4 Jul->4
46months4new Dict(), These are the officialy approved strings that represent special terms allowed
for input of BoT,EoT,NK,NV,NVI,TODAY. (Match if term starts with input.)
13needsBuildtrue, flag if needs to be initialised
39shortcutsnew Dict(), B->BoT,E->EoT etc
43specialTermsnew Dict(), shortcuts are the shortest string that identifies a special term eg E for EoT
These are generated from the .3 items in section 1 of the appendix for
BoT,EoT,NK,NV,NVI,TODAY. (Match if input starts with shortcut)
14yearLimit4095, Maximum size of year

DAYi.js

DAYi - INTERVAL

DAYi

13constructorInitialiser Standard constructor
Initialiser can be
an array See .FromArray()
a number See .From32Bits()
a string See .FromString();
a DAYi object to create a clone
439AsDays Convert an interval into days
Result may be fractional and negative
322ClearWWWS Clear .whatWentWrongStr
422Day Returned UNSIGNED number of days. This might be >31
NOTE Always ise this when accessing the 'd' element as we may be storing a number of days.
NOTE This is not the same as AsDays();
462DumpStr
111FromInitialiser Try to load from given Initialiser
Return false if the Initialiser was readable but gave strange values
  • Unsuitable object passed to DAYi constructor
  • Unsuitable value passed to DAYi constructor
278From32BitsUnsignedInt Read native 32-bit format
Sets DAY from number
bits 31 - 29 Signature 0:NVI 1:INT
bits 28 Sign 0:-ve 1:+ve
bits 27 - 16 Years 0..4095
bits 15 - 12 Months 0..11
bits 11 - 7 Days 0..31
bit 6 (not used)
bits 5 - 3 Interval precision code (DAYu.INTTYPE_...)
bits 2 - 0 Error code 0..7
  • Invalid signature in DAYi.From32Bits()
32FromArrayDayArray The lowest level 'constructor', all the other From() methods feed into this.
Initialiser is an array 'Signature,Sign,Years,Months,Days,ErrorCode';
.Signature must be DAYu.INT or DAYu.NVI
.Sign must be DAYu.pos or DAYu.neg
.Years , .Months and .Days may be 0,-1 or a sensible value
-1 is used to indicate missing. For example a string of "+1y 2m"
would have a -1 for .Days. This important for precision
For example "+1y 2m" is precice to month but "+1y 2m 0d" is precise to day
.ErrorCode is ignored unless .Signature is NVI
  • DAYi.FromArray expects INT or NVI signature
137FromStringIntStr
  • DAYi.FromString() needs a string
  • Incorrect format for DAYi.FromString()
325GetErrorCode what is the numerical value of the error
320GetWWWS Get .whatWentWrongStr
329HasDay
328HasMonth
330HasYear
452IsSmallerThanAnInterval
  • DAYi.IsSmallerThan() needs an interval
327IsValid
417Month
101Precision The .Precision() of an interval tells which of d, m or y it is accurate to
This is nearly but not quite the same as .Type() qv.
253SetYearYear Set Year and deal with negative values
82Sign
81Signature
303To32Bits
351ToStringForceFull Creates a string something like +1y 2m 3d
Used without argument (or if ForceFull is falsey) missing
elements will be left out. So this can result in outputs
such as +2m The default operation is not to show elements
of greater precision than of the interval. So yearly precision
drops the m and y parts. Intervals stored as days only are
displayed as +123 etc.
Use ForceFull to always show all elements. This can help to
make it clearer to read columns etc. The year will normally
have a single digit and the m and d fields two so that in general
columns are likely to line-up.
NOTE
When ForceFull is used with a day-only interval it will be
displayed in a y-m-d format with excess days being converted
to months and years. This is only for display, the actual
value of the DAYi object is not affected.
95Type The .Type() of an interval can be
INTTYPE_DDD : Days are stored as-is without converting to months/years
INTTYPE_Y : precise to year
INTTYPE_M : precise to month
INTTYPE_D : precise to day
IMPORTANT .Type() gives the underlying storage method while .Precision()
returns the same value for INTTYPE_DDD and INTTYPE_D
410Year returns a SIGNED year number
71_Reset
203_Sanitize _Sanitize
Private method to ensure internal values are safe
If any errors then sanitize them and set signature to NV
Return false if any errors found
Tell error to .whatWentWrongStr
61_SetDDDDays
318_WWWSNewErrorStr Add error message to .whatWentWrongStr
NewErrorStr should be of the form: 'current routine' message

DAYx.js

Development and testing only
============================
"use strict"; var DAYx,DAYu,DAYo,$,DAYc,console; only for occasional extra linting

StackExpAct

19constructorExp
Act
~~~~~~~~~~~~~ Used by library methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Stack expected and actual results
NB Don't forget to do Exp='' afterwards

StartsWith

10constructorHaystack
Needle
~~~~~~~~~~~~~ Used by library methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
case insensitive string comparison

DAYx

351AddBadTestResultLineNum,Task,Expected,Actual,Comment will be obs
359AddCommentResultComment
355AddGoodTestResultLineNum,Task,Expected,Actual,Comment will be obs
645AddLibraryTestTestName,Desc,InpArg,OutArg,FunCode Add a test function to the library
TestName will be capitalised
Desc is description/purpose (Any authoring/versioning stuff will be
comments in the code calling this.
InpArg and OutArg describe the sort of input, ie bit in the brackets
of a test line, and nature of expected result.
FunCode is the actual code
NOTE We use the variable DAYx.__FILE__ to inject the source file name
This is normally set/cleared by the methods loader.
312AddResultOk,TestData,Result,Comment Add an entry to the results file
Ok is boolean or array of 'Ok,TestData,Result'
818AjaxForFilesPath,Ext,ThenDo Look for a list of files using AJAX call
Path is relative eg './tests/scripts'
Extension is type of file incl dot eg .testScript
ThenDo is a function taking an array of filenames which
have had their extensions removed
*NOTE* Browser only
837AjaxLoadMethodFiles look in the methods directory for js files
each should have one or more methods implemented
by AddLibraryTest(). All these are eval-ed
so as to populate the method library
----------------------------------------------------------
44DayDisplayD =============================================
Return HTML for the inner state of the DAYo object
=============================================
624DescribeLibraryTestsInHtml List the tests in the library
If InHtml is truthy then return a string of TRs else an
array of 'Name,Desc,Input,Output,Filename'
673DoTestLineTestData =============================================
TestData is 'TestName,Function arguments,Expected result string,Comment'
Do the appropriate test and add to results
=============================================
89ErrorCodeToTextErrCode =============================================
Return the text representation of the ErrorCode(number)
=============================================
369GetNextTestLine =============================================
Looks for the next line in the tests that contains an actual
test. Return null if 'EOF' or array
'TestName,Function arguments,Expected result string,Comment'
=============================================
160InitAtSubstitutions set @TODAY and @YEAR substitutions
----------------------------------
301OutputLabel,Values Send debugging information to results listing
Can be toggled by the .showOutput property
Label is a string
Values is an array of bits to show
109RunTestsInBrowserFileName =============================================
BROWSER MAIN CALL
Load the file of tests into an array of lines
tests'n' will be the nth line of the file
Uses jQuery
=============================================
173RunTestsInNodeFileName,Fs,Path =============================================
NODE MAIN CALL
FileName is relative to current dir
Fs is fs (file system) variable
Path is path utility
=============================================
68SigToTextSignature =============================================
Return the text representation of the signature(number)
=============================================
758TestDateBothWaysTestData =============================================
Implements the DATEBOTHWAYS test
=============================================
458TestResultsTableShowAll =============================================
Returns HTML for a table of results (BROWSER)
=============================================
784TestSetConfigTestData =============================================
Implements the SETCONFIG command (Not actually a test)
Normal use : SETCONFIG(KEY,VALUE)
Can be used for functions eg SETCONFIG(SetLimitToUnixExtended)
=============================================
709TestTwoWaysDay This combines to/from js Date, to/from 32bits, to/from extended unix
the result is ok or D, 3, U! being the first failure in the both ways
We have this as a general add-on to the other tests so we get lots of coverage
We expect these to be pretty reliable... OK Hope... OK wish :)
434WrapS,Width
594_BarText,Width pad/truncate cell value and add a leading bar
552_DumpResultsToFileShowAll Writes results to file.
either <script>.fails or <script>.results depending on ShowAll
Filename is in 1st line testResults
Node only
420_ErrorPlaceEx Return string giving line and file where exception happened
*** (Probably FF only. Alternatives at http://eriwen.com/javascript/js-stack-trace/)
613_UnZeroNumStr Utility function to drop trailing decimal zeroes
from a number-string. "123.000" --\> "123" "123.400" --\> "123.4"
232_UpdateOverview update the collection of statistics
This is an HTML file with links to results
Node only
34__FILE__'', Used when reading-in methods
32atToday'', substitution for @TODAY
33atYear'', substitution for @YEAR
35firstLine1,
30glines'', temp
36lastLine9999,
24libMethods{}, library of available tests
31scriptName'', full name of file being used
39showOutputtrue, show results of .Output()
28testFailCount0,
29testPassCount0,
27testResults[], results of tests
26tests[], definition of test
This reference document is completely self-contained so download and put with your other data sheets.
Created 22 Oct 16 at 15:22:38 Source from http://vulpeculox.net Written by Peter Fox @