Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Integration tests (tests/Integration) inside a real Nextcloud server, on
# every database Nextcloud supports for apps: SQLite, MySQL, MariaDB and
# PostgreSQL, for the oldest and the newest supported Nextcloud version.
#
# Each job checks out nextcloud/server, puts this app into its apps/ folder,
# installs Nextcloud on the job's database and runs the tests with the
# server's own PHPUnit version.
name: Integration tests

on:
pull_request:
push:
branches: [master]

permissions:
contents: read

concurrency:
group: integration-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
integration:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
server: ['stable31', 'stable35']
database:
- name: SQLite
type: sqlite
image: ''
port: 3306
options: ''
- name: MySQL 8.4
type: mysql
image: mysql:8.4
port: 3306
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 10
- name: MariaDB 11.4
type: mysql
image: mariadb:11.4
port: 3306
options: --health-cmd="mariadb-admin ping" --health-interval 5s --health-timeout 2s --health-retries 10
- name: PostgreSQL 16
type: pgsql
image: postgres:16
port: 5432
options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 10

name: ${{ matrix.database.name }}, Nextcloud ${{ matrix.server }}

services:
# Not started for SQLite (empty image)
database:
image: ${{ matrix.database.image }}
ports:
- 4444:${{ matrix.database.port }}/tcp
env:
MYSQL_ROOT_PASSWORD: rootpassword
POSTGRES_USER: root
POSTGRES_PASSWORD: rootpassword
# The installer connects to this database before it would create it
POSTGRES_DB: nextcloud
options: ${{ matrix.database.options }}

steps:
- name: Checkout Nextcloud server
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
repository: nextcloud/server
ref: ${{ matrix.server }}
submodules: true
path: server

- name: Checkout app
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
path: server/apps/timetracker

- name: Set up php
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2
with:
php-version: '8.3'
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite, mysql, pdo_mysql, pgsql, pdo_pgsql
coverage: none
ini-file: development
ini-values: disable_functions=""

- name: Install the server's PHPUnit
run: composer install --no-progress --working-dir=server/vendor-bin/phpunit

- name: Use strict GROUP BY rules (MySQL, MariaDB)
if: matrix.database.type == 'mysql'
run: echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword

- name: Install Nextcloud and enable the app
working-directory: server
run: |
mkdir data
php occ maintenance:install --verbose --database=${{ matrix.database.type }} --database-name=nextcloud \
--database-host=127.0.0.1 --database-port=4444 --database-user=root --database-pass=rootpassword \
--admin-user admin --admin-pass admin
php occ app:enable timetracker

- name: Run integration tests
working-directory: server/apps/timetracker
run: ../../vendor-bin/phpunit/vendor/bin/phpunit -c phpunit.integration.xml
4 changes: 2 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Unit tests only, against the nextcloud/ocp stub package — no live
# Nextcloud server or database is booted, which keeps this job fast and free
# of external services. tests/Integration (real server + DB) is intentionally
# not run here; see the linked GitHub issue for the multi-database follow-up.
# of external services. tests/Integration (real server + DB) runs in
# integration.yml.
name: PHPUnit

on:
Expand Down
30 changes: 21 additions & 9 deletions lib/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1250,18 +1250,30 @@ public function deleteGoal($id) {
return $this->getGoals();
}

/**
* The user's time zone. Goal periods use it, like the report grouping in
* ReportItemMapper does.
*/
private function userTimeZone(): \DateTimeZone {
return \OCP\Server::get(\OCA\TimeTracker\Service\UserTimeZone::class)->get($this->userId);
}

/**
* Monday 00:00 of the ISO week containing $timestamp, in the user's time zone.
*/
public function getStartOfWeek($timestamp){
$date = new \DateTime('@'.$timestamp);
$weeknumber = $date->format("W");
$year = $date->format("Y");
$weekstartdt = new \DateTime();
$weekstartdt->setTime(0, 0, 0, 0);
$weekstartdt->setISODate($year, $weeknumber);

return $weekstartdt;
$date = (new \DateTime('@'.$timestamp))->setTimezone($this->userTimeZone());
// "o" is the ISO year that week "W" belongs to: 30 Dec 2024 is in week 1 of 2025
$date->setISODate((int)$date->format('o'), (int)$date->format('W'));
$date->setTime(0, 0, 0, 0);

return $date;
}
/**
* The 1st of the month containing $timestamp, 00:00 in the user's time zone.
*/
public function getStartOfMonth($timestamp){
$date = new \DateTime('@'.$timestamp);
$date = (new \DateTime('@'.$timestamp))->setTimezone($this->userTimeZone());
$date->modify('first day of this month');
$date->setTime(0, 0, 0, 0);

Expand Down
Loading
Loading