Why is the value changing if the stream has not been restarted in over time
“updated_at”:“2017-10-10T17:06:08.489043Z”
Under what conditions is it changing? if you change the game? name? or description?
i use this https://api.twitch.tv/kraken/streams/
Yes
Basically many things can cause updated_at to change.
And how either you can find the start time of the stream, and only
The “created_at” value can be used to find the start time of the stream, note that this is the “created_at” value that relates to the stream and not the one relating to the channel. The API returns information about the stream and includes the channel details as well.
Thank you, it seems you are right, didn’t notice it because the information transmitted about the time is transmitted in a different time zone
All times are in UTC, I wrote an uptime calculator in .js and had to do some work to make sure the times I displayed accounted for the timezones of the user.
I suggest this lovely library: countdown.js (Docs)
This is roughly how I use it in my Node bot:
const countdown = require('countdown');
// Bitwise OR these constants together. Comes out to the number 158.
// (You could just put 158 if you want my config)
const agoUnits = [ 'SECONDS', 'MINUTES', 'HOURS', 'DAYS', 'YEARS' ]
.reduce((p, n) => p |= countdown[n], 0);
// Applicable labels
const countdownLabels = '|s|m|h|d|||y|||';
// Apply the labels to singular and plural, space delimiter, and a default of "0s" for empty.
countdown.setLabels(countdownLabels, countdownLabels, ' ', ' ', '0s');
function ago(start, end = Date.now(), addSuffix = true) {
// Parse start, get the value.
start = new Date(start).getTime();
// Parse end, default to now
end = end === null ? Date.now() : new Date(end).getTime();
// If a date is not valid, it was NaN
if(start !== start || end !== end) { // NaN check
return null;
}
// Get our Timespan object
let c = countdown(start, end, agoUnits);
// Convert to a string
let cStr = c.toString();
// Add a nice suffix
if(addSuffix) {
cStr += ' ' + (c.value < 0 ? 'ago' : 'from now');
}
return cStr;
}
module.exports = { ago };
Example
const { ago } = require('./lib/utils');
let time = ago(stream.created_at);
console.log('Stream started', time);
// Stream started 4h 3m 28s ago
let time = ago(stream.created_at, null, false);
console.log('Stream started', time);
// Stream started 4h 3m 28s
// Without disabling the suffix in this order, it would add "from now"
let time = ago(stream.created_at, stream.channel.created_at, false);
console.log('Stream started', time, 'after the account was created');
// Stream started 6y 241d 18h 2s after the account was created
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.