-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file_name_format: Unix? #5
Comments
You need to configure a file sensor, like this |
I may be missing something, but in the attached Git I can't find no reference about the Unix to Human readable format conversion, only sorting(?) |
Yes, you are right. But currently I don’t have enough time to develop this feature. Feel free to do a pull request if you know how to develop it. |
Thanks anyway. |
Yes, that's the right place |
Here's a snippet that convert Unix timestamps to function processUnixFileName(fileName) {
const unixPattern = /^[0-9]+-[0-9]+\.mp4$/;
if (unixPattern.test(fileName)) {
const timestamp = fileName.split("-")[0];
const date = new Date(parseInt(timestamp, 10) * 1000); // Convert Unix timestamp to Date object
const formattedDate = formatDateToYYYYMMDDHHmmss(date);
return formattedDate;
} else {
return fileName; // If not Unix format, return the original fileName
}
}
function formatDateToYYYYMMDDHHmmss(date) {
const yyyy = date.getFullYear();
const mm = String(date.getMonth() + 1).padStart(2, '0');
const dd = String(date.getDate()).padStart(2, '0');
const hh = String(date.getHours()).padStart(2, '0');
const min = String(date.getMinutes()).padStart(2, '0');
const ss = String(date.getSeconds()).padStart(2, '0');
return `${yyyy}${mm}${dd}-${hh}${min}${ss}`;
}
// Example usage
const fileName = "1721398175-1721398267.mp4";
const result = processUnixFileName(fileName);
console.log(result); // Outputs in the YYYYMMDD-HHmmss format: 20240719-140935 If I'm correctly reading your code it should be sufficient to add those two functions and call |
My files come in the following format:
1721398175-1721398267.mp4
, where the two numbers are Unix formatted dates and times, which seems not to be supported by the card.I can cut the “start” date using
file_name_date_begins: 11
, but I would need a “Unix” option implemented. I noticed in the docs some datetime difference functionality already implemented with theAGO
function, so it seems like the necessary libraries are already in place.Thanks for your time and the beautiful card.
The text was updated successfully, but these errors were encountered: