aboutsummaryrefslogtreecommitdiffstats
path: root/build/tasks/build.js
blob: bd07364ea36521bbe8898511f9e0563378a8bdca (plain)
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
"use strict";

module.exports = function( grunt ) {

grunt.registerTask( "clean", function() {
	require( "rimraf" ).rimrafSync( "dist" );
} );

grunt.registerTask( "asciilint", function() {
	var valid = true,
		files = grunt.file.expand( { filter: "isFile" }, "ui/*.js" );
	files.forEach( function( filename ) {
		var i, c,
			text = grunt.file.read( filename );

		// Ensure files use only \n for line endings, not \r\n
		if ( /\x0d\x0a/.test( text ) ) {
			grunt.log.error( filename + ": Incorrect line endings (\\r\\n)" );
			valid = false;
		}

		// Ensure only ASCII chars so script tags don't need a charset attribute
		if ( text.length !== Buffer.byteLength( text, "utf8" ) ) {
			grunt.log.error( filename + ": Non-ASCII characters detected:" );
			for ( i = 0; i < text.length; i++ ) {
				c = text.charCodeAt( i );
				if ( c > 127 ) {
					grunt.log.error( "- position " + i + ": " + c );
					grunt.log.error( "-- " + text.substring( i - 20, i + 20 ) );
					break;
				}
			}
			valid = false;
		}
	} );
	if ( valid ) {
		grunt.log.ok( files.length + " files lint free." );
	}
	return valid;
} );

};
Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib/Service/BirthdateParserService.php
blob: 8234161b3d8a2de1388c93cb051594d73e1293bc (plain)
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
<?php

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCA\User_LDAP\Service;

use DateTimeImmutable;
use Exception;
use InvalidArgumentException;

class BirthdateParserService {
	/**
	 * Try to parse the birthdate from LDAP.
	 * Supports LDAP's generalized time syntax, YYYYMMDD and YYYY-MM-DD.
	 *
	 * @throws InvalidArgumentException If the format of then given date is unknown
	 */
	public function parseBirthdate(string $value): DateTimeImmutable {
		// Minimum LDAP generalized date is "1994121610Z" with 11 chars
		// While maximum other format is "1994-12-16" with 10 chars
		if (strlen($value) > strlen('YYYY-MM-DD')) {
			// Probably LDAP generalized time syntax
			$value = substr($value, 0, 8);
		}

		// Should be either YYYYMMDD or YYYY-MM-DD
		if (!preg_match('/^(\d{8}|\d{4}-\d{2}-\d{2})$/', $value)) {
			throw new InvalidArgumentException("Unknown date format: $value");
		}

		try {
			return new DateTimeImmutable($value);
		} catch (Exception $e) {
			throw new InvalidArgumentException(
				"Unknown date format: $value",
				0,
				$e,
			);
		}
	}
}