API Analytics - Date Math
Having accurate date math is critical for any reporting tool. Because most Moesif customers are utilizing Moesif for business metrics, the Moesif platform leverages calendar aligned date system. This means all dates are aligned to the calendar system. This means:
- Last 1 minute will start at top of the minute
- Last 1 hour will start at top of hour
- Last 1 day will start at 12am of that day
- Last 1 week will start at 12am of the first day of the week
- Last 1 month will start at 12am of the first day of the month
“from” or “after” dates will round to the beginning of the period. This means if you say “last 1 day”, Moesif will round to 12am at the beginning of that day
“to” or “before” dates will round to the end of that period which is effectively the last millisecond before the next period. For example, if you say before 1 day ago, Moesif will translate this to 23:59:999 of the day before.
Moesif always includes the period that your are filtering. This means if you filter “from 1 week ago to 1 week ago” and today is 10-22, Moesif will translate to 2022-10-10T07:00:00.000 to 2022-10-17T06:59:59.999 assuming your app was configured for PST timezone.
Moesif will always display a full period. This means if you filter on “last week”, Moesif will start the data set at 12am of the first day of the first full week. For example, let’s say today is Tuesday and your start of week is Monday, Moesif will start the period 8 days ago at 12am.
By default, Moesif will use the locale info from your browser settings for the timezone/start of week. To ensure all team members are seeing the same data regardless of location, it’s recommend to define a global timezone and start of week for your apps. This can be done by editing the apps settings under “App and Team” settings. See docs on how to do this
Changing time zone or week starts on will not update previously saved workspaces and tags. However, you can copy or re-save any existing workspaces to ensure they use your latest settings.
API Query Params
Many of the APIs have a
?from= and a
?to= parameter for filtering the dataset.
These parameters can either take in an absolute date as a ISO formatted string or a relative date expression.
For relative dates, Moesif will parse relatives dates using the following format:
The following units are supported:
nowfor current time
For example, to specify 1 day ago, this can be as
On the other hand if you want 1 day from now (in the future), this would be
+1d or can be shortened to
now is a special alias for the current time.
While the API defaults to UTC timezone, you should specify the
?time_zone parameter to ensure histograms and other metrics consider the correct timezone.