File size: 1,315 Bytes
c562e21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
export const getInitials = (name) => {
  if (!name) return 'МЫ';
  const parts = name.trim().split(/\s+/);
  if (parts.length >= 2) {
    return (parts[0][0] + parts[1][0]).toUpperCase();
  }
  return name.slice(0, 2).toUpperCase();
};

export const getAvatarColorClass = (name) => {
  if (!name) return 'avatar-color-0';
  let hash = 0;
  for (let i = 0; i < name.length; i++) {
    hash = name.charCodeAt(i) + ((hash << 5) - hash);
  }
  const colorIndex = Math.abs(hash) % 6; // 6 pre-defined gradients
  return `avatar-color-${colorIndex}`;
};

export const formatDueDate = (timestamp) => {
  if (!timestamp) return null;
  const date = new Date(timestamp);
  const today = new Date();
  today.setHours(0, 0, 0, 0);
  const tomorrow = new Date(today);
  tomorrow.setDate(tomorrow.getDate() + 1);

  const checkDate = new Date(date);
  checkDate.setHours(0, 0, 0, 0);

  const timeString = date.toLocaleTimeString('ru-RU', {
    hour: '2-digit',
    minute: '2-digit',
  });

  if (checkDate.getTime() === today.getTime()) {
    return `Сегодня в ${timeString}`;
  } else if (checkDate.getTime() === tomorrow.getTime()) {
    return `Завтра в ${timeString}`;
  }

  return (
    date.toLocaleDateString('ru-RU', {
      day: 'numeric',
      month: 'short',
    }) + ` в ${timeString}`
  );
};