Class: NotionRubyMapping::DateBaseProperty
- Includes:
- IsEmptyIsNotEmpty
- Defined in:
- lib/notion_ruby_mapping/properties/date_base_property.rb
Overview
Date base property (date, created_time, last_edited_time, formula)
Direct Known Subclasses
CreatedTimeProperty, DateProperty, FormulaProperty, LastEditedTimeProperty, RollupProperty
Instance Attribute Summary
Attributes inherited from Property
#name, #property_cache, #property_id, #will_update
Class Method Summary collapse
-
.date_from_obj(obj) ⇒ Date?
Iso8601 format string.
- .start_end_time(date) ⇒ Object
-
.value_str(obj, start_time: false, end_time: false) ⇒ String?
Iso8601 format string.
Instance Method Summary collapse
-
#filter_after(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_before(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_does_not_equal(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_equals(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_next_month(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_next_week(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_next_year(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_on_or_after(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_on_or_before(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_past_month(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_past_week(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_past_year(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#filter_this_week(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Generated Query object.
-
#value_str(obj, start_time: false, end_time: false) ⇒ String?
Iso8601 format string.
Methods included from IsEmptyIsNotEmpty
#filter_is_empty, #filter_is_not_empty
Methods inherited from Property
#assert_database_property, #assert_page_property, #clear_will_update, #contents?, create_from_json, #database?, #initialize, #make_filter_query, #new_name=, #page?, #property_schema_json, #remove, #retrieve_page_property, #type, #update_from_json, #update_property_schema_json
Constructor Details
This class inherits a constructor from NotionRubyMapping::Property
Class Method Details
.date_from_obj(obj) ⇒ Date?
Returns iso8601 format string.
42 43 44 45 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 42 def self.date_from_obj(obj) str = value_str obj Date.parse str if str end |
.start_end_time(date) ⇒ Object
34 35 36 37 38 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 34 def self.start_end_time(date) ds = date.iso8601 tz = Time.now.strftime "%:z" %w[00:00:00 23:59:59].map { |t| [ds, "T", t, tz].join("") } end |
.value_str(obj, start_time: false, end_time: false) ⇒ String?
Returns iso8601 format string.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 12 def self.value_str(obj, start_time: false, end_time: false) case obj when DateTime obj.iso8601 when Date tz = Time.now.strftime "%:z" ds = obj.iso8601 if start_time "#{ds}T00:00:00#{tz}" elsif end_time "#{ds}T23:59:59#{tz}" else ds end when Time obj.strftime("%Y-%m-%dT%H:%M:%S%:z") else obj end end |
Instance Method Details
#filter_after(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
96 97 98 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 96 def filter_after(date, condition: nil, another_type: nil) make_filter_query "after", value_str(date, end_time: true), condition: condition, another_type: another_type end |
#filter_before(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
88 89 90 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 88 def filter_before(date, condition: nil, another_type: nil) make_filter_query "before", value_str(date, start_time: true), condition: condition, another_type: another_type end |
#filter_does_not_equal(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 69 def filter_does_not_equal(date, condition: nil, another_type: nil) if date.class == Date start_date, end_date = self.class.start_end_time date if condition filter_before(start_date, condition: condition, another_type: another_type) .or(filter_after(end_date, condition: condition, another_type: another_type)) else filter_before(start_date, another_type: another_type) .or(filter_after(end_date, another_type: another_type)) end else make_filter_query "does_not_equal", value_str(date), condition: condition, another_type: another_type end end |
#filter_equals(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 51 def filter_equals(date, condition: nil, another_type: nil) if date.class == Date start_date, end_date = self.class.start_end_time date if condition filter_after(start_date, condition: condition, another_type: another_type) .and(filter_before(end_date, condition: condition, another_type: another_type)) else filter_after(start_date, another_type: another_type) .and(filter_before(end_date, another_type: another_type)) end else make_filter_query "equals", value_str(date), condition: condition, another_type: another_type end end |
#filter_next_month(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
162 163 164 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 162 def filter_next_month(condition: nil, another_type: nil) make_filter_query "next_month", {}, condition: condition, another_type: another_type end |
#filter_next_week(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
154 155 156 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 154 def filter_next_week(condition: nil, another_type: nil) make_filter_query "next_week", {}, condition: condition, another_type: another_type end |
#filter_next_year(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
170 171 172 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 170 def filter_next_year(condition: nil, another_type: nil) make_filter_query "next_year", {}, condition: condition, another_type: another_type end |
#filter_on_or_after(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
113 114 115 116 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 113 def filter_on_or_after(date, condition: nil, another_type: nil) make_filter_query "on_or_after", value_str(date, start_time: true), condition: condition, another_type: another_type end |
#filter_on_or_before(date, condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
104 105 106 107 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 104 def filter_on_or_before(date, condition: nil, another_type: nil) make_filter_query "on_or_before", value_str(date, end_time: true), condition: condition, another_type: another_type end |
#filter_past_month(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
130 131 132 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 130 def filter_past_month(condition: nil, another_type: nil) make_filter_query "past_month", {}, condition: condition, another_type: another_type end |
#filter_past_week(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
122 123 124 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 122 def filter_past_week(condition: nil, another_type: nil) make_filter_query "past_week", {}, condition: condition, another_type: another_type end |
#filter_past_year(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
138 139 140 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 138 def filter_past_year(condition: nil, another_type: nil) make_filter_query "past_year", {}, condition: condition, another_type: another_type end |
#filter_this_week(condition: nil, another_type: nil) ⇒ NotionRubyMapping::Query
Returns generated Query object.
146 147 148 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 146 def filter_this_week(condition: nil, another_type: nil) make_filter_query "this_week", {}, condition: condition, another_type: another_type end |
#value_str(obj, start_time: false, end_time: false) ⇒ String?
Returns iso8601 format string.
176 177 178 |
# File 'lib/notion_ruby_mapping/properties/date_base_property.rb', line 176 def value_str(obj, start_time: false, end_time: false) self.class.value_str(obj, start_time: start_time, end_time: end_time) end |