Skip to content

Commit

Permalink
Add function to convert Android colorInt to hex
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikkabade committed Mar 12, 2024
1 parent a4c1023 commit 4283785
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/hooks/Functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,30 @@ export function getDate(date: any) {
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
return `${months[m.getMonth()]} ${m.getDate()}`;
}
export function getYear(date: any){
export function getYear(date: any) {
const y = new Date(date);
return y.toISOString().slice(0,4)
return y.toISOString().slice(0, 4)
}
export function getMonth(date: any){
export function getMonth(date: any) {
const y = new Date(date);
return y.toISOString().slice(5,7)
return y.toISOString().slice(5, 7)
}
export function androidColorToHex(androidColor: any) {
// Ensure the input is treated as an unsigned 32-bit integer
let color = androidColor >>> 0;

// Extract ARGB components
let alpha = (color >> 24) & 0xFF;
let red = (color >> 16) & 0xFF;
let green = (color >> 8) & 0xFF;
let blue = color & 0xFF;

// Convert to hex string and pad with zeros if necessary
let hexColor = "#" +
alpha.toString(16).padStart(2, '0') +
red.toString(16).padStart(2, '0') +
green.toString(16).padStart(2, '0') +
blue.toString(16).padStart(2, '0');

return hexColor.toUpperCase(); // Return the hex color code
}

0 comments on commit 4283785

Please sign in to comment.