Php webtags: Difference between revisions

1,547 bytes added ,  17:15, 26 June 2020
m
Line 64: Line 64:
=== Locale issues ===
=== Locale issues ===


*Some locales use decimal commas, that is in any real numbers a comma separates the integer and decimal parts. So people in these locales expect to see any output in that format. However, to perform arithmetic on a number many script languages need that number to use a full stop as the separator for the decimal part.
Remember the script variables generated from web tags may be used in two different ways:
**Cumulus makes available a selection of web tags with a "RC" prefix where the comma (if any used) is removed and the output always uses a decimal point (like a full stop).  
 
** Many ready-made scripts present both the "RC" and normal versions of such tags, they have to enclose all tags (even numeric ones) in quotes so the locale does not worry about format
==== For direct output on a web page ====
** Having numeric values in quotes makes it more difficult to do arithmetic with them, and may insert unwanted leading zeroes.
 
**If you are writing your own script, decide if you want to leave out quotes round web tags that always produce numeric output (not true for all that can produce numeric output, they might output '-' in some cases like first day of a month.
*Some locales use decimal commas, that is in any real numbers a comma separates the integer and decimal parts. So people in these locales expect to see any output in that format.  
*Those writing scripts have to decide whether to treat
*# as numeric output as a number (with either decimal comma or decimal point), which can be easily output and won't have unnecessary zeroes (leading or trailing zeroes won't appear in the output).
*# or to treat as text (the Cumulus web-tag is enclosed in quotes), this is obviously needed if numbers can be replaced by hyphens when that web tag is not actually set (e.g. some monthly web tags are no set until at least one full day exists for that month); but this might mean the output includes leading or trailing zeroes.
 
==== For use in calculations, or Ajax updates ====
 
* You might want to vary the output, depending on the content of one of these script variables:
**Maybe you vary the look of a page depending on whether it is being viewed during daytime or at night
**Maybe you only want to display snow details when it has actually snowed
**Maybe you want to display time of last rain when that is today, but not if there has been no rain this month.
**Maybe you want to calculate a derivative not available as a script variable
**Maybe you want to use the script variables to plot a graph (or some other transformation that requires a script to action)
*In all these cases, you are probably going to feed these script variables into another script, but to perform arithmetic on a number many script languages need that number to use a full stop as the separator for the decimal part.
**Cumulus 1 makes available a selection of web tags with a "RC" prefix where the comma (if any used) is removed and the output always uses a decimal point (like a full stop).
**The more recent version of MX allow a "rc=y" parameter than replaces any commas in the output with a full stop, this parameter is now available on any web tag that can output a number with decimal places.
* Many ready-made scripts present both the "RC" and normal versions of such tags, they have to enclose all tags (even numeric ones) in quotes so the locale does not worry about format
** Having numeric values in quotes makes it possible the script variable includes unwanted leading zeroes, and that in turn makes it possible that any other script processing that variable might not recognise it as a number or might guess it is to base 16 instead of base 10.
 
====Different locales may express dates differently====


*Different locales may express dates differently
** Some ready-made scripts assume that the separator between parts of the date are "/" and hard code the alternative outputs with that assumption (perhaps replacing "/" with ".").
** Some ready-made scripts assume that the separator between parts of the date are "/" and hard code the alternative outputs with that assumption (perhaps replacing "/" with ".").
**Many ready-made scripts are derived from one written assuming the USA date format is being used with month before day of month, and year last. Of course Cumulus actually outputs dates either in the format used by the locale selected or in the ISO format of year first with hyphens between date parts.
**Many ready-made scripts are derived from one written assuming the USA date format is being used with month before day of month, and year last.  
**Yet there are relatively few Cumulus users in the USA, and therefore the majority of Cumulus users want either day of month or year first.
**Of course Cumulus actually outputs dates either in the format used by the locale selected or in the ISO format of year first with hyphens between date parts.
** Check your choice of read-made script can cope with dates in the format you prefer.
** Check your choice of read-made script can cope with dates in the format you prefer.
**If you are writing your own script, decide what date format you want. It will look better if all dates on a page are in same format.


==== Time format =====
*Do you prefer 24-hour clock (some call this timetable format or military format) or 12 hour clock with am/pm?
*Do you prefer 24-hour clock (some call this timetable format or military format) or 12 hour clock with am/pm?
**Some ready made scripts may express times in both formats so you can choose the format you want
**Some ready made scripts may express times in both formats so you can choose the format you want


If there are dates and times to output, Cumulus changes the date for certain web tags for times between midnight and rollover time (if 9am or 10am). Be sure you understand how any ready-made script is reporting combinations of date and time. If you are writing your own script, bear this in mind.
If there are dates and times to output, Cumulus changes the date for certain web tags for times between midnight and rollover time (if 9am or 10am). Be sure you understand how any ready-made script is reporting combinations of date and time.


=== station and/or sensor specific tags ===
=== station and/or sensor specific tags ===
5,838

edits