This commit is contained in:
parent
9132b33e91
commit
4aae45f13b
10 changed files with 588 additions and 180 deletions
19
mirea-specific/mireaweek.nix
Normal file
19
mirea-specific/mireaweek.nix
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# Утилита расчёта номера учебной недели.
|
||||
# Даты отсечки семестров (9 февраля / 1 сентября) специфичны для МИРЭА,
|
||||
# поэтому пакет живёт здесь, а не в общем mireadesktop.
|
||||
{ pkgs }:
|
||||
pkgs.stdenv.mkDerivation rec {
|
||||
pname = "mireaweek";
|
||||
version = "0.1.0";
|
||||
src = ./weekday.kt;
|
||||
dontInstall = true;
|
||||
dontUnpack = true;
|
||||
nativeBuildInputs = [ pkgs.kotlin ];
|
||||
buildPhase = ''
|
||||
mkdir -p $out/{bin,lib}
|
||||
kotlinc $src -include-runtime -d mireaweek.jar
|
||||
mv mireaweek.jar $out/lib
|
||||
printf "${pkgs.jre}/bin/java -jar $out/lib/mireaweek.jar" > $out/bin/mireaweek
|
||||
chmod +x $out/bin/mireaweek
|
||||
'';
|
||||
}
|
||||
15
mirea-specific/tint2-widget.nix
Normal file
15
mirea-specific/tint2-widget.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Виджет панели tint2, показывающий номер учебной недели МИРЭА.
|
||||
# Подставляется в mireadesktop через параметр extraTint2Widgets.
|
||||
{ mireaweek }:
|
||||
''
|
||||
#-------------------------------------
|
||||
execp = new
|
||||
execp_name = mireaweek
|
||||
execp_command = ${mireaweek}/bin/mireaweek
|
||||
execp_interval = 0
|
||||
execp_font = mono 10
|
||||
execp_font_color = #dddddd 100
|
||||
execp_centered = 1
|
||||
execp_has_icon = 0
|
||||
execp_padding = 5 5
|
||||
''
|
||||
27
mirea-specific/university.nix
Normal file
27
mirea-specific/university.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
# University names
|
||||
# May be written any language
|
||||
#
|
||||
# Название университета
|
||||
# Может быть на любом языке
|
||||
name = "МИРЭА — Российский технологический университет";
|
||||
|
||||
# short name should be in english
|
||||
# короткое название должно быть на английском
|
||||
shortName = "MIREA";
|
||||
|
||||
# NixOS installer branding
|
||||
# Брендирование установщика NixOS
|
||||
isoName = "mirea-nixos-installer.iso";
|
||||
installerBin = "mirea-install";
|
||||
|
||||
# LEGALS: I am NOT a creator on wallpaper.svg,
|
||||
# I do NOT own wallpaper.svg, this doesn't represent any of my ideas or views,
|
||||
# that's just a logo (a coat of arms to be precise) of a university,
|
||||
# and it is in the public domain.
|
||||
#
|
||||
# ОТКАЗ ОТ ОТВЕТСТВЕННОСТИ:
|
||||
# Я не являюсь владельцем файла wallpaper.svg, его добавление не репрезентует моих идей или взглядов,
|
||||
# это просто логотип (точнее герб) университета, и он является общественным достоянием.
|
||||
wallpaper = ./wallpaper.svg;
|
||||
}
|
||||
1
mirea-specific/wallpaper.svg
Normal file
1
mirea-specific/wallpaper.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 689 KiB |
52
mirea-specific/weekday.kt
Normal file
52
mirea-specific/weekday.kt
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import java.time.DayOfWeek
|
||||
import java.time.LocalDate
|
||||
import java.time.Month
|
||||
|
||||
enum class Period {
|
||||
Autumn,
|
||||
Winter,
|
||||
Spring
|
||||
}
|
||||
|
||||
fun determinePeriod(today: LocalDate): Period {
|
||||
val februaryCutoff = LocalDate.of(today.year, Month.FEBRUARY, 9)
|
||||
val septemberCutoff = LocalDate.of(today.year, Month.SEPTEMBER, 1)
|
||||
|
||||
return when {
|
||||
today.isBefore(februaryCutoff) -> Period.Winter
|
||||
today.isAfter(septemberCutoff.minusDays(1)) -> Period.Autumn
|
||||
else -> Period.Spring
|
||||
}
|
||||
}
|
||||
|
||||
fun calculateWeek(period: Period, date: LocalDate): String {
|
||||
return when {
|
||||
period == Period.Winter -> "Хороших праздников, удачной сессии!"
|
||||
date.dayOfWeek == DayOfWeek.SUNDAY -> "Сегодня воскресенье, лучше иди домой"
|
||||
else -> {
|
||||
val currentWeek = date.getWeekOfYear()
|
||||
val periodLimit = when (period) {
|
||||
Period.Spring -> LocalDate.of(date.year, Month.FEBRUARY, 9)
|
||||
Period.Autumn -> LocalDate.of(date.year, Month.SEPTEMBER, 1)
|
||||
else -> throw IllegalStateException("Unexpected period")
|
||||
}
|
||||
val limitWeek = periodLimit.getWeekOfYear()
|
||||
val isLimitSunday = periodLimit.dayOfWeek == DayOfWeek.SUNDAY
|
||||
|
||||
val weekOffset = if (isLimitSunday) 1 else 0
|
||||
val weekNumber = 1 + currentWeek - limitWeek - weekOffset
|
||||
"$weekNumber неделя"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun LocalDate.getWeekOfYear(): Int {
|
||||
return this.get(java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val today = LocalDate.now()
|
||||
val period = determinePeriod(today)
|
||||
val weekInfo = calculateWeek(period, today)
|
||||
println(weekInfo)
|
||||
}
|
||||
Loading…
Reference in a new issue