Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
2cfe5c42
Commit
2cfe5c42
authored
26 years ago
by
Mirar (Pontus Hagland)
Browse files
Options
Downloads
Patches
Plain Diff
oops, forgot this file.
Rev: lib/modules/Calendar.pmod/module.pmod:1.1
parent
68fa39cb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Calendar.pmod/module.pmod
+116
-0
116 additions, 0 deletions
lib/modules/Calendar.pmod/module.pmod
with
116 additions
and
0 deletions
lib/modules/Calendar.pmod/module.pmod
0 → 100644
+
116
−
0
View file @
2cfe5c42
//! module Calendar
//!
//! This module implements calendar calculations, and base classes
//! for time units.
//!
//! example program:
//! <pre>
//! void write_month(object m)
//! {
//! object w;
//! object today;
//!
//! today=function_object(object_program(m))->Day();
//!
//! write(sprintf(" %|28s\n",
//! Simulate.capitalize(m->name()+" ")
//! +m->year()->name()));
//!
//! w=m->day(1)->week();
//!
//! write(" ");
//! foreach (Array.map(w->days(),w->day)->week_day_name(),string n)
//! write(sprintf("%3s ",n[0..2]));
//! write("\n");
//!
//! do
//! {
//! array a;
//! object d;
//! a=Array.map(Array.map(w->days(),w->day),
//! lambda(object d,object m)
//! { if (d->month()!=m) return 0; else return d; },m);
//!
//! write(sprintf("%3s ",w->name()));
//! foreach (a,d)
//! if (d)
//! if (d!=today) write(sprintf(" %2d ",d->month_day()));
//! else write(sprintf(">%2d<",d->month_day()));
//! else write(" ");
//!
//! write("\n");
//! w++;
//! }
//! while (w->day(0)->month()==m);
//! }
//! </pre>
//! call with, for example,
//! <tt>write_month(Calendar.Swedish.Month());</tt>.
//!
//! class time_unit
//!
//! method array(string) lesser()
//! Gives a list of methods to get lesser (shorter) time units.
//! ie, for a month, this gives back <tt>({"day"})</tt>
//! and the method <tt>day(mixed n)</tt> gives back that
//! day object. The method <tt>days()</tt> gives back a
//! list of possible argument values to the method <tt>day</tt>.
//! Concurrently, <tt>Array.map(o->days(),o->day)</tt> gives
//! a list of day objects in the object <tt>o</tt>.
//!
//!
//! Ie:<pre>
//! array(string) lesser() - gives back a list of possible xxx's.
//! object xxxs() - gives back a list of possible n's.
//! object xxx(mixed n) - gives back xxx n
//! object xxx(object(Xxx) o) - gives back the corresponing xxx
//! </pre>
//!
//! The list of n's (as returned from xxxs) are always in order.
//!
//! There are two n's with special meaning, 0 and -1.
//! 0 always gives the first xxx, equal to
//! my_obj->xxx(my_obj->xxxs()[0]), and -1 gives the last,
//! equal to my_obj->xxx(my_obj->xxxs()[-1]).
//!
//! To get all xxxs in the object, do something like
//! <tt>Array.map(my_obj->xxxs(),my_obj->xxx)</tt>.
//!
//! xxx(object) may return zero, if there was no correspondning xxx.
//!
//! method array(string) greater()
//! Gives a list of methods to get greater (longer) time units
//! from this object. For a month, this gives back <tt>({"year"})</tt>,
//! thus the method <tt>month->year()</tt> gives the year object.
//!
//! method object next()
//! method object prev()
//! method object `+(int n)
//! method object `-(int n)
//! method object `-(object x)
//! next and prev gives the logical next and previous object.
//! The <tt>+</tt> operator gives that logical relative object,
//! ie <tt>my_day+14</tt> gives 14 days ahead.
//! <tt>-</tt> works the same way, but can also take an object
//! of the same type and give the difference as an integer.
#define error(X) throw(({(X),backtrace()}))
class _TimeUnit
{
object this=this_object();
array(string) greater() { return ({}); }
array(string) lesser() { return ({}); }
int `<(object x) { error("'< undefined\n"); }
int `>(object x) { error("'> undefined\n"); }
int `==(object x) { error("'== undefined\n"); }
object `+(int n) { error("`+ undefined\n"); }
object|int `-(int n) { error("`- undefined\n"); }
object next() { return this+1; }
object prev() { return this+(-1); }
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment