Difference between revisions of "Historical age"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
m
(Convert to Template:Function2 format, use Template:SeeAlso/Mall Prices, add JS sample code)
Line 1: Line 1:
{{
+
<onlyinclude>{{{{{format|Function2}}}
#vardefine:name|historical_age}}{{
+
|name=historical_age
#vardefine:return_type|float}}{{
+
|function1.return_type=float
 
+
|function1.description=Returns the age of the price returned by {{f|historical_age}} in days.
FunctionPage|
+
|function1.param1=shop_for
name={{#var:name}}|
+
|function1.param1.type=item
 +
|function1.param1.description=Item to check for
 +
|description=The return value is in days. For example, a return value of 0.5 means that the price is 12 hours old.
 +
|code1={{CodeSample
 +
  |title=Code Samples
 +
  |description=This function returns a price no more than 18 hours old by checking {{f|mall_price}} if {{f|historical_price}} is older than that.
 +
  |code=
 +
{{{!}} class="wikitable"
 +
! style="width: 50%" {{!}} ASH
 +
! style="width: 50%" {{!}} JavaScript
 +
{{!}}- style="vertical-align: top"
 +
{{!}}
 +
<syntaxhighlight lang="d" line highlight="2">
 +
int check_price( item shopfor ) {
 +
  if ( historical_age( shopfor ) > .75 )
 +
      return mall_price( shopfor );
 +
  return historical_price( shopfor );
 +
}
 +
</syntaxhighlight>
 +
{{!}}
 +
<syntaxhighlight lang="js" line highlight="5">
 +
const { historicalAge, historicalPrice, mallPrice } = require("kolmafia");
  
function1={{Function|
+
function checkPrice(shopfor) {
name={{#var:name}}|
+
  if (historicalAge(shopfor) > .75)
aggregate={{#var:aggregate}}|
+
    return mallPrice(shopfor);
return_type={{#var:return_type}}|
+
  return historicalPrice(shopfor);
return_also={{#var:return_also}}|
 
parameter1={{Param|item|shop_for}}|
 
p1desc={{Pspan|shop_for}} for which to check the price's age|
 
}}|
 
 
 
function_description=Returns the age of the price that [[historical_price|historical_price()]] will return. The return value is in days, so a returned value of 1.25 means that the price is 1 day and 6 hours old.|
 
 
 
code1={{CodeSample|
 
title=Code Samples|
 
description=Returns a price no more than 18 hours old by checking mall_price() if the historical_price() is older than that.|
 
code=
 
<syntaxhighlight>
 
int check_price(item shopfor) {
 
  if(historical_age(shopfor) > .75)
 
      return mall_price(shopfor);
 
  return historical_price(shopfor);
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
}}|
+
{{!}}}
 
+
  |moreinfo=
see_also={{SeeAlso|historical_price|mall_price}}|
 
 
}}
 
}}
 
+
|see_also={{SeeAlso/Mall Prices}}
 +
|cli_equiv=
 +
|more_info=
 +
|special=
 +
|{{{1|}}}
 +
}}</onlyinclude>
 
[[Category:Item Management]]
 
[[Category:Item Management]]

Revision as of 15:06, 31 December 2020

Function Syntax

float historical_ageitem shop_for )

Returns the age of the price returned by historical_age() in days.
  • shop_for: Item to check for

The return value is in days. For example, a return value of 0.5 means that the price is 12 hours old.

Code Samples

This function returns a price no more than 18 hours old by checking mall_price() if historical_price() is older than that.

ASH JavaScript
1 int check_price( item shopfor ) {
2    if ( historical_age( shopfor ) > .75 )
3       return mall_price( shopfor );
4    return historical_price( shopfor );
5 }
1 const { historicalAge, historicalPrice, mallPrice } = require("kolmafia");
2 
3 function checkPrice(shopfor) {
4   if (historicalAge(shopfor) > .75)
5     return mallPrice(shopfor);
6   return historicalPrice(shopfor);
7 }

See Also

historical_age() | historical_price() | mall_price() | mall_prices()