MDL-41792 block_calendar_upcoming: tidy existing code
[moodle.git] / calendar / classes / type_base.php
CommitLineData
2f00e1b2 1<?php
2f00e1b2
MN
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
022745ac
MN
17namespace core_calendar;
18
2f00e1b2
MN
19/**
20 * Defines functions used by calendar type plugins.
21 *
22 * This library provides a unified interface for calendar types.
23 *
24 * @package core_calendar
2f00e1b2
MN
25 * @copyright 2008 onwards Foodle Group {@link http://foodle.org}
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
022745ac 28abstract class type_base {
2f00e1b2
MN
29
30 /**
31 * Returns a list of all the possible days for all months.
32 *
33 * This is used to generate the select box for the days
34 * in the date selector elements. Some months contain more days
35 * than others so this function should return all possible days as
36 * we can not predict what month will be chosen (the user
37 * may have JS turned off and we need to support this situation in
38 * Moodle).
39 *
40 * @return array the days
41 */
42 public abstract function get_days();
43
44 /**
45 * Returns a list of all the names of the months.
46 *
47 * @return array the month names
48 */
49 public abstract function get_months();
50
51 /**
52 * Returns the minimum year of the calendar.
53 *
54 * @return int the minumum year
55 */
56 public abstract function get_min_year();
57
58 /**
59 * Returns the maximum year of the calendar.
60 *
61 * @return int the max year
62 */
63 public abstract function get_max_year();
64
f59ab4ad
MN
65 /**
66 * Returns a formatted string that represents a date in user time.
67 *
68 * @param int $date the timestamp in UTC, as obtained from the database
69 * @param string $format strftime format
70 * @param int|float|string $timezone the timezone to use
71 * {@link http://docs.moodle.org/dev/Time_API#Timezone}
72 * @param bool $fixday if true then the leading zero from %d is removed,
73 * if false then the leading zero is maintained
74 * @param bool $fixhour if true then the leading zero from %I is removed,
75 * if false then the leading zero is maintained
76 * @return string the formatted date/time
77 */
78 public abstract function timestamp_to_date_string($date, $format, $timezone, $fixday, $fixhour);
79
80 /**
81 * Given a $time timestamp in GMT (seconds since epoch), returns an array that represents
82 * the date in user time.
83 *
84 * @param int $time timestamp in GMT
85 * @param float|int|string $timezone the timezone to use to calculate the time
86 * {@link http://docs.moodle.org/dev/Time_API#Timezone}
87 * @return array an array that represents the date in user time
88 */
89 public abstract function timestamp_to_date_array($time, $timezone);
90
2f00e1b2
MN
91 /**
92 * Provided with a day, month, year, hour and minute in the specific
93 * calendar type convert it into the equivalent Gregorian date.
94 *
95 * @param int $year
96 * @param int $month
97 * @param int $day
98 * @param int $hour
99 * @param int $minute
100 * @return array the converted day, month and year.
101 */
102 public abstract function convert_to_gregorian($year, $month, $day, $hour = 0, $minute = 0);
103
104 /**
105 * Provided with a day, month, year, hour and minute in a Gregorian date
106 * convert it into the specific calendar type date.
107 *
108 * @param int $year
109 * @param int $month
110 * @param int $day
111 * @param int $hour
112 * @param int $minute
113 * @return array the converted day, month and year.
114 */
115 public abstract function convert_from_gregorian($year, $month, $day, $hour = 0, $minute = 0);
2f00e1b2 116}