chronos 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/CHANGELOG.rdoc +27 -0
  2. data/HISTORY.rdoc +4 -0
  3. data/LICENSE.txt +52 -0
  4. data/MANIFEST.txt +51 -0
  5. data/NOTES.rdoc +85 -0
  6. data/README.rdoc +125 -0
  7. data/Rakefile +34 -0
  8. data/TODO.rdoc +63 -0
  9. data/bench/completebench.rb +24 -0
  10. data/ext/cchronos/extconf.rb +5 -0
  11. data/ext/chronos_core/extconf.rb +5 -0
  12. data/lib/chronos.rb +208 -0
  13. data/lib/chronos/calendar.rb +16 -0
  14. data/lib/chronos/calendar/gregorian.rb +94 -0
  15. data/lib/chronos/data/zones.tab +424 -0
  16. data/lib/chronos/datetime.rb +299 -0
  17. data/lib/chronos/datetime/gregorian.rb +698 -0
  18. data/lib/chronos/duration.rb +141 -0
  19. data/lib/chronos/duration/gregorian.rb +261 -0
  20. data/lib/chronos/durationtotext.rb +42 -0
  21. data/lib/chronos/exceptions.rb +16 -0
  22. data/lib/chronos/gregorian.rb +27 -0
  23. data/lib/chronos/interval.rb +132 -0
  24. data/lib/chronos/interval/gregorian.rb +80 -0
  25. data/lib/chronos/locale/parsers/de_CH.rb +50 -0
  26. data/lib/chronos/locale/parsers/en_US.rb +1 -0
  27. data/lib/chronos/locale/parsers/generic.rb +21 -0
  28. data/lib/chronos/locale/strings/de_DE.yaml +76 -0
  29. data/lib/chronos/locale/strings/en_US.yaml +76 -0
  30. data/lib/chronos/minimalistic.rb +37 -0
  31. data/lib/chronos/numeric/gregorian.rb +100 -0
  32. data/lib/chronos/ruby.rb +6 -0
  33. data/lib/chronos/version.rb +21 -0
  34. data/lib/chronos/zone.rb +212 -0
  35. data/rake/initialize.rb +116 -0
  36. data/rake/lib/assesscode.rb +59 -0
  37. data/rake/lib/bonesplitter.rb +245 -0
  38. data/rake/lib/projectclass.rb +69 -0
  39. data/rake/tasks/copyright.rake +24 -0
  40. data/rake/tasks/gem.rake +119 -0
  41. data/rake/tasks/git.rake +40 -0
  42. data/rake/tasks/loc.rake +33 -0
  43. data/rake/tasks/manifest.rake +63 -0
  44. data/rake/tasks/meta.rake +16 -0
  45. data/rake/tasks/notes.rake +36 -0
  46. data/rake/tasks/post_load.rake +18 -0
  47. data/rake/tasks/rdoc.rake +73 -0
  48. data/rake/tasks/rubyforge.rake +67 -0
  49. data/rake/tasks/spec.rake +55 -0
  50. data/spec/bacon_helper.rb +43 -0
  51. data/spec/lib/chronos/datetime/gregorian_spec.rb +314 -0
  52. data/spec/lib/chronos/datetime_spec.rb +219 -0
  53. data/spec/lib/chronos_spec.rb +91 -0
  54. metadata +111 -0
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = 0.0.4
2
+ === 7th July, 2007
3
+
4
+ * Improved C code (thanks to chris2)
5
+ * Added default value for alpha in ::floats methods
6
+ * Fixed a typo in mixer.rb
7
+
8
+ = 0.0.3
9
+ === 7th July, 2007
10
+
11
+ * Added documentation to .rb files
12
+ * Moved +/- for most classes to Color::Common
13
+ * Improved Rakefile
14
+ * Basic implementation of Color::Named
15
+ * Added as_floats argument to #to_hash methods
16
+ * Added ::floats to most color classes
17
+
18
+ = 0.0.2
19
+ === 6th July, 2007
20
+
21
+ * Fixed Color::Common#with
22
+ * Corrected the Rakefile
23
+
24
+ = 0.0.1
25
+ === 6th July, 2007
26
+
27
+ * Initial release of the color classes implemented in C and Ruby.
data/HISTORY.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2008-03-03
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/LICENSE.txt ADDED
@@ -0,0 +1,52 @@
1
+ The Chronos library is copyrighted free software by Stefan Rusterholz.
2
+ You can redistribute it and/or modify it under the terms o the conditions
3
+ below (also known as the 'Ruby License'):
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict
21
+ with standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial).
42
+
43
+ 5. The scripts and library files supplied as input to or produced as
44
+ output from the software do not automatically fall under the
45
+ copyright of the software, but belong to whomever generated them,
46
+ and may be sold commercially, and may be aggregated with this
47
+ software.
48
+
49
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
50
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
51
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52
+ PURPOSE.
data/MANIFEST.txt ADDED
@@ -0,0 +1,51 @@
1
+ CHANGELOG.rdoc
2
+ HISTORY.rdoc
3
+ LICENSE.txt
4
+ MANIFEST.txt
5
+ NOTES.rdoc
6
+ README.rdoc
7
+ Rakefile
8
+ TODO.rdoc
9
+ bench/completebench.rb
10
+ lib/chronos.rb
11
+ lib/chronos/calendar.rb
12
+ lib/chronos/calendar/gregorian.rb
13
+ lib/chronos/data/zones.tab
14
+ lib/chronos/datetime.rb
15
+ lib/chronos/datetime/gregorian.rb
16
+ lib/chronos/duration.rb
17
+ lib/chronos/duration/gregorian.rb
18
+ lib/chronos/durationtotext.rb
19
+ lib/chronos/exceptions.rb
20
+ lib/chronos/gregorian.rb
21
+ lib/chronos/interval.rb
22
+ lib/chronos/interval/gregorian.rb
23
+ lib/chronos/locale/parsers/de_CH.rb
24
+ lib/chronos/locale/parsers/en_US.rb
25
+ lib/chronos/locale/parsers/generic.rb
26
+ lib/chronos/locale/strings/de_DE.yaml
27
+ lib/chronos/locale/strings/en_US.yaml
28
+ lib/chronos/minimalistic.rb
29
+ lib/chronos/numeric/gregorian.rb
30
+ lib/chronos/ruby.rb
31
+ lib/chronos/version.rb
32
+ lib/chronos/zone.rb
33
+ rake/initialize.rb
34
+ rake/lib/assesscode.rb
35
+ rake/lib/bonesplitter.rb
36
+ rake/lib/projectclass.rb
37
+ rake/tasks/copyright.rake
38
+ rake/tasks/gem.rake
39
+ rake/tasks/git.rake
40
+ rake/tasks/loc.rake
41
+ rake/tasks/manifest.rake
42
+ rake/tasks/meta.rake
43
+ rake/tasks/notes.rake
44
+ rake/tasks/post_load.rake
45
+ rake/tasks/rdoc.rake
46
+ rake/tasks/rubyforge.rake
47
+ rake/tasks/spec.rake
48
+ spec/bacon_helper.rb
49
+ spec/lib/chronos/datetime/gregorian_spec.rb
50
+ spec/lib/chronos/datetime_spec.rb
51
+ spec/lib/chronos_spec.rb
data/NOTES.rdoc ADDED
@@ -0,0 +1,85 @@
1
+ = NOTES
2
+
3
+ == Daylight Savings Time (DST)
4
+ * Math operations will keep the DST sticky, even if the resulting datetime would have a different
5
+ result for dst?.
6
+ Example:
7
+ cest_0230 = Datetime.civil(2008,10,26,2,30).in("CEST") # => 2008-10-26T02:30:00+02:00
8
+ cest_0330 = cest_0230+1.hour # => 2008-10-26T03:30:00+02:00
9
+ cet_0230 = Datetime.civil(2008,10,26,2,30).in("CET") # => 2008-10-26T02:30:00+01:00
10
+ cet_0330 = Datetime.civil(2008,10,26,3,30).in("CET") # => 2008-10-26T03:30:00+01:00
11
+ normalized = cest_0330.normalized_dst # => 2008-10-26T02:30:00+01:00
12
+ cest_0230.dst? # => true
13
+ cest_0330.dst? # => false
14
+ cet_0230.dst? # => false
15
+ cet_0330.dst? # => false
16
+ normalized.dst? # => false
17
+ cest_0330.timezone.name # => "CEST"; adding a duration will keep the timezone
18
+ (cest_0330 - cest_0330).hours # => 0
19
+ (cest_0330 - cest_0230).hours # => 1
20
+ (cet_0330 - cest_0330).hours # => 1
21
+ (cet_0330 - cest_0230).hours # => 2
22
+ normalized == cest_0330 # => true (== only checks day_number and ps_number)
23
+ normalized.eql?(cest_0330) # => false (eql? additionally checks timezone and language)
24
+ * Deviating from the above, DST does not influence math:
25
+ result = somedatetime + Duration.new(:hours => 2)
26
+ result.hour == somedatetime.hour+2
27
+ Is guaranteed to be true, no matter whether you cross a DST border there.
28
+ If we respected DST, it could be +1, +2 or +3, depending on whether we cross the DST
29
+ border in one or the other direction or not at all.
30
+ * DST being active can be checked by Datetime#dst?, which returns true/false if a DST rule
31
+ is applicable and nil if no DST rule is applicable. No rule being applicable is the case
32
+ for dates in the future (since the DST rules might change) and for timezones which simply
33
+ don't have DST.
34
+ * Getting the datetime in the timezone with the correct DST applied is done via #normalized_dst
35
+ E.g. if you got a result from an addition, subtraction, parsing that gives you a datetime
36
+ with timezone CEST (which implies DST is true) but at a date where DST is off, you can
37
+ use #normalized_dst and the resulting Datetime will be in CET (which implies DST is false)
38
+
39
+ == Leap seconds
40
+ * Leap seconds do not influence math
41
+ result = somedatetime + Duration.new(:seconds => 60)
42
+ result.minute = somedatetime.minute+1
43
+ Is guaranteed to be true. If we respected leap seconds for calculations, this would
44
+ not be guaranteed since a minute could have 61 seconds (when you cross the leap second).
45
+ * Parsing a datetime which has the leapsecond set will be treated as the normal 60 value for
46
+ second (which means 'infinitesimally shortly before the change to the next minute')
47
+
48
+ == Leap years
49
+ * Leap years DO influence math
50
+ result = somedatetime + Duration.new(:days => 365)
51
+ result.year = somedatetime.year + 1
52
+ Is NOT guaranteed to be true.
53
+
54
+ == Infinitesimally shortly before change of the bigger unit
55
+ * You can express a time infinitesimally shortly before the same time with one unit switching
56
+ (e.g. hour switching from 1 to 2) by specifying the next smaller unit to max+1.
57
+ Example:
58
+ a = Datetime.today.at(12,59,59.9999999)
59
+ b = Datetime.today.at(12,60)
60
+ c = Datetime.today.at(13,00)
61
+ a < b # => true
62
+ b < c # => true
63
+
64
+ == Subtracting a datetime from a datetime
65
+ * Subtracting a datetime from another will result in an Interval
66
+ * Intervals have the guaranteed property of Interval#start <= Interval#end
67
+ * Converting a gregorian Interval to a Duration will create a gregorian Duration, using both, months
68
+ and picoseconds (the alternative choice would have been to use picoseconds only).
69
+ * The direction is preserved, so if datetime_a < datetime_b and you do
70
+ datetime_a - datetime_b
71
+ Then the resulting Interval's start will be datetime_a, its end will be datetime_b. All units will
72
+ be positive. But the moment you convert it to a Duration, the units will be negative.
73
+
74
+ == The problem with +/- and datetimes/durations
75
+ * Adding and subtracting durations to and from datetimes depends on the operands.
76
+ This means that adding a duration to a datetime and subtracting the same duration from the
77
+ result can result in a new datetime that is not equal to the original datetime:
78
+ (a_datetime + a_duration) - a_duration == a_datetime # is NOT guaranteed to be true
79
+ An example where this happens:
80
+ a = Datetime.civil(2007,1,31) # => 2007-01-31
81
+ b = a + 1.month # => 2007-02-28
82
+ c = b - 1.month # => 2007-01-28
83
+ a == c # => false
84
+ Nota bene: datetime + (duration - duration) == datetime # IS guaranteed, since
85
+ duration - duration will result in a zero duration.
data/README.rdoc ADDED
@@ -0,0 +1,125 @@
1
+ = Chronos
2
+
3
+
4
+
5
+ == INDEXING
6
+ Name:: Chronos
7
+ Gem:: chronos
8
+ Summary:: Library to deal with Date, Time, Durations and Intervals.
9
+ Author:: Stefan Rusterholz <stefan.rusterholz+chronos at gmail.com>
10
+ Version:: 0.1.1
11
+ Website:: http://chronos.rubyforge.org/
12
+ Git Repository:: http://github.com/apeiros/chronos
13
+ Bugtracker:: http://rubyforge.org/tracker/?atid=25774&group_id=6649&func=browse
14
+ Feature Requests:: http://rubyforge.org/tracker/?atid=25777&group_id=6649&func=browse
15
+ License:: Ruby License (see LICENSE.txt)
16
+
17
+
18
+
19
+ == SUMMARY
20
+ Chronos is a library that lets you easily deal with various kinds of calculations
21
+ with dates, times, durations and intervals.
22
+
23
+
24
+
25
+ == DESCRIPTION
26
+ (none yet)
27
+
28
+
29
+
30
+ == IMPORTANT
31
+ Date, Time and Duration don't satisfy usual algebraic laws. Many operations are a
32
+ matter of definition. It is very likely that your expectation might be broken at
33
+ some points. Read the NOTES.rdoc for ambiguous cases and how they are solved in
34
+ Chronos.
35
+
36
+
37
+
38
+ == INSTALLING
39
+ === Via RubyGems
40
+ You need for the installation:
41
+ * rubygems >= 1.2.0
42
+
43
+ You need for some of the rake tasks:
44
+ * bacon
45
+ * flexmock
46
+ * git
47
+ * hpricot
48
+ * rcov
49
+ * rdiscount (or markdown)
50
+ * rdoc
51
+ * rspec
52
+
53
+ To install, do:
54
+
55
+ gem install chronos
56
+
57
+ Note: you might have to use 'sudo gem install chronos'
58
+
59
+ === From Github
60
+ You need for the installation:
61
+ * rubygems >= 1.2.0
62
+
63
+ You need for some of the rake tasks:
64
+ * bacon
65
+ * flexmock
66
+ * git
67
+ * hpricot
68
+ * rcov
69
+ * rdiscount (or markdown)
70
+ * rdoc
71
+ * rspec
72
+
73
+ To install, do:
74
+
75
+ curl -L -o chronos.tgz http://github.com/apeiros/chronos/tarball/master
76
+ tar -xfz chronos.tgz
77
+ cd apeiros-chronos-<big number here>/
78
+ rake gem:install
79
+
80
+ Note: you might have to use 'sudo rake gem:install'
81
+
82
+
83
+
84
+ == EXAMPLES
85
+ See in the examples directory for code examples.
86
+
87
+
88
+
89
+ == DESIGN
90
+ === General
91
+ In general for all structures there are calendary-agnostic classes. Those are directly
92
+ defined within the Chronos module. The calendary specific subclasses are then defined
93
+ as ::Chronos::+Classname+::+Calendarname+. There are shortcuts defined via specific requires.
94
+ E.g. if you require 'chronos/+calendarname+' it will map all
95
+ ::Chronos::+Classname+::+Calendarname+ to ::+Classname+ for convenience.
96
+
97
+ === Datetime
98
+ A datetime is a point on the axis of time. This axis has an origin (zero point). For chronos this
99
+ origin is defined to be backdated gregorian datetime 0000-01-01T00:00:00Z. The units to measure
100
+ the distance from this origin is days+picoseconds, where 8.64e16 picoseconds is 1 day.
101
+ The calendar specific classes then can represent that date/time in the units defined for that
102
+ calendar, such as gregorian can represent that distance from origin as
103
+ year-month-day"T"hour:minute:second.fraction±offset.
104
+ Timezone and DST are only representational offsets on top of that distance. That means that
105
+ 2008-01-01T12:00Z and 2008-01-01T14:00+02:00 have the same distance, but are represented
106
+ differently due to the different offset. Just as "May" (english) and "Mai" (german) are
107
+ different representations of the same month.
108
+ So Datetime and all its subclasses store date and time without representational offsets, those
109
+ are only respected when accessing calendary-specific values, such as month, day, hour etc.
110
+
111
+
112
+
113
+ == CREDITS
114
+ Yukihiro "Matz" Matsumoto:: For ruby
115
+ Jarrett C.:: Helping with the C implementation
116
+ Various People:: For rubygems, rake, all the support in #ruby-lang, #ruby-pro and the ruby-talk ML
117
+
118
+
119
+
120
+ == LINKS
121
+ Website:: http://chronos.rubyforge.org/
122
+ Git Repository:: http://github.com/apeiros/chronos
123
+ Report a bug:: http://rubyforge.org/tracker/?func=add&group_id=6649&atid=25774
124
+ Request a feature:: http://rubyforge.org/tracker/?func=add&group_id=6649&atid=25777
125
+ ISO 8601:: http://en.wikipedia.org/wiki/ISO_8601
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ #--
2
+ # Copyright 2007-2008 by Stefan Rusterholz.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+
8
+
9
+ # Look in the rake/initialize.rb file for the various options that can be
10
+ # configured in this Rakefile. The .rake files in the rake/tasks directory
11
+ # are where the options are used.
12
+ require 'rake/initialize'
13
+
14
+ # The default task
15
+ task :default => 'spec:run'
16
+
17
+
18
+
19
+ # Project details (defaults are in rake/initialize, some cleanup is done per section in the
20
+ # prerequisite task in each .task file, some other cleanup is done in post_load.rake)
21
+ Project.meta.name = 'chronos'
22
+ Project.meta.version = version_proc("Chronos::VERSION")
23
+ Project.meta.website = 'http://chronos.rubyforge.org/'
24
+ Project.meta.bugtracker = 'http://'
25
+ Project.meta.feature_requests = 'http://'
26
+ Project.meta.use_git = true
27
+
28
+ # TODO: remove chronos_core from this list later
29
+ Project.manifest.exclude += %w[ext/cchronos/**/* ext/chronos_core/**/*]
30
+
31
+ Project.rdoc.exclude += %w[lib/**/*.yaml ext/**/*]
32
+
33
+ Project.rubyforge.project = 'chronos'
34
+ Project.rubyforge.path = 'chronos'
data/TODO.rdoc ADDED
@@ -0,0 +1,63 @@
1
+ = BUGS
2
+ * Datetime with timezones having positive offsets picoseconds becomes negative and days & overflow
3
+ are wrong
4
+
5
+ = TODO
6
+ == Pre-Release
7
+ * Validate Datetime API
8
+ * Refactor Interval (Gregorian)
9
+ * Test rake tasks and temporarly remove non-working or fix
10
+ * Complete specs
11
+ * Complete minimal docs
12
+
13
+ == Low priority
14
+ * Verify all rake tasks
15
+ * Fix gem rake task (must validate manifest and version)
16
+ * Rake task to help localization
17
+ * Spec to test completeness of localizations
18
+ * Write extensive parsing suite, there should be 4 kinds of parsers:
19
+ * Extremely strict format specific parsers, such as Chronos::Datetime::Gregorian::iso8601 which
20
+ parses only and only iso8601 compliant strings and raises if it fails.
21
+ * User defined strict parsers which use a Parser::Format (or a string which the parser method
22
+ converts to a Parser::Format instance) to determine the parsing rules which raise if they fail
23
+ to match.
24
+ * Strict automatic parser +Classname+::parse, which tries predetermined formats and
25
+ raises if it fails to consume the whole string.
26
+ * Lax automatic parser (no name yet, maybe just a switch to ::parse) which do "as good as
27
+ possible" matching and conversion and defaultize whatever is missing and never raise.
28
+ * Write extensive #format suite with proper localization
29
+ * Localize words ('month', 'months', ...)
30
+ * Localize numerics ('one', 'two', ...)
31
+ * Localize entities ('January', ..., 'Monday', ...)
32
+ * Localize format (mm/dd/YYYY, dd.mm.YYYY, ...)
33
+ * Lazy loading of strings/parsers/formatters
34
+ * chronos/replace/time - Allow Chronos::Datetime::Gregorian to act as a Time drop-in
35
+ * chronos/replace/date - Allow Chronos::Datetime::Gregorian to act as a Date drop-in
36
+ * chronos/compat/time - Allow Chronos::Duration::Gregorian to work seamlessly with Time
37
+ * chronos/compat/date - Allow Chronos::Duration::Gregorian to work seamlessly with Date
38
+ * Import Scheduler
39
+ * Handle recurring
40
+ * Natural language parsers
41
+ * Extractors (extract datetimes, intervals and durations from plaintext)
42
+ * Improve formatters
43
+ * Add other calendary systems
44
+ * Chinese
45
+ * Jewish
46
+ * Indian
47
+ * Julian
48
+ * Discordian
49
+ * Full documentation, including guides/howtos/caveeats
50
+
51
+
52
+ = UNHAPPY
53
+ * DateTime#strftime("%Z") does not indicate if it's in a timezone with active DST or not,
54
+ so importing a DateTime and importing a Time will give different results.
55
+ * Freeze datetime/duration/interval
56
+
57
+ == WHAT I WANT
58
+ All changes to the source MUST NOT violate any of the following statements:
59
+
60
+ * Multiple calendar systems can be used at the same time
61
+ * If a single calendar system is used, (almost) all of the complexity of supporting multiple
62
+ calendars is hidden
63
+ * Chronos is multilingual