Changes

Jump to navigation Jump to search
→‎Dates: add comparison, copyedit & tweak examples
Line 493: Line 493:  
'''This is a proposed API that may be part of SMAPI 1.15. It's only available in preview versions of SMAPI and may change before release.'''
 
'''This is a proposed API that may be part of SMAPI 1.15. It's only available in preview versions of SMAPI and may change before release.'''
   −
Use <tt>SDate</tt> for calculating in-game dates. You start by creating a basic date:
+
Use <tt>SDate</tt> for calculating in-game dates. You start by creating a date:
 
<source lang="c#">
 
<source lang="c#">
// get the current date
+
var date = SDate.Now(); // current date
var date = SDate.Now();
+
var date = new SDate(28, "spring"); // date in the current year
 
+
var date = new SDate(28, "spring", 2); // get a date in the given year
// get a date in the current year
  −
var date = new SDate(28, "spring");
  −
 
  −
// get a date in the given year
  −
var date = new SDate(28, "spring", 2);
   
</source>
 
</source>
   −
You can calculate offsets from any date:
+
Then you can calculate offsets from any date:
 
<source lang="c#">
 
<source lang="c#">
 
// add days
 
// add days
Line 512: Line 507:  
// subtract days
 
// subtract days
 
new SDate(01, "spring", 2).AddDays(-1); // 28 winter in year 1
 
new SDate(01, "spring", 2).AddDays(-1); // 28 winter in year 1
 +
</source>
 +
 +
...and compare dates:
 +
<source lang="c#">
 +
var a = new SDate(01, "spring");
 +
var b = new SDate(02, "spring");
 +
if (a < b) // true
 +
  ...
 
</source>
 
</source>
    
Note that <tt>SDate</tt> won't let you create invalid dates:
 
Note that <tt>SDate</tt> won't let you create invalid dates:
 
<source lang="C#">
 
<source lang="C#">
// ArgumentException: Invalid day '-1', must be a value from 1 to 28.
+
// ArgumentException: Invalid day '30', must be a value from 1 to 28.
new SDate(-1, "spring");
+
new SDate(30, "spring");
    
// ArithmeticException: Adding -1 days to 01 spring Y1 would result in invalid date 28 winter Y0.
 
// ArithmeticException: Adding -1 days to 01 spring Y1 would result in invalid date 28 winter Y0.
new SDate(1, "spring", 1).AddDays(-1);
+
new SDate(01, "spring", 1).AddDays(-1);
 
</source>
 
</source>
  
translators
8,438

edits

Navigation menu