Class: Code::Object::Time
- Inherits:
-
Code::Object
- Object
- Code::Object
- Code::Object::Time
- Defined in:
- lib/code/object/time.rb
Constant Summary collapse
- DEFAULT_ZONE =
"Etc/UTC"
Constants inherited from Code::Object
Instance Attribute Summary
Attributes included from Concerns::Shared
Class Method Summary collapse
Instance Method Summary collapse
- #call(**args) ⇒ Object
- #code_add(year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil) ⇒ Object
- #code_after?(other = nil) ⇒ Boolean
- #code_april? ⇒ Boolean
- #code_august? ⇒ Boolean
- #code_before?(other = nil) ⇒ Boolean
- #code_change(year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil) ⇒ Object
- #code_current ⇒ Object
- #code_day ⇒ Object
- #code_days ⇒ Object
- #code_december? ⇒ Boolean
- #code_february? ⇒ Boolean
- #code_format(format, locale: nil) ⇒ Object
- #code_friday? ⇒ Boolean
- #code_future? ⇒ Boolean
- #code_hour ⇒ Object
- #code_hours ⇒ Object
- #code_january? ⇒ Boolean
- #code_july? ⇒ Boolean
- #code_june? ⇒ Boolean
- #code_march? ⇒ Boolean
- #code_may? ⇒ Boolean
- #code_minute ⇒ Object
- #code_minutes ⇒ Object
- #code_monday? ⇒ Boolean
- #code_month ⇒ Object
- #code_months ⇒ Object
- #code_november? ⇒ Boolean
- #code_now ⇒ Object
- #code_october? ⇒ Boolean
- #code_past? ⇒ Boolean
- #code_saturday? ⇒ Boolean
- #code_second ⇒ Object
- #code_seconds ⇒ Object
- #code_september? ⇒ Boolean
- #code_substract(year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil) ⇒ Object
- #code_sunday? ⇒ Boolean
- #code_thursday? ⇒ Boolean
- #code_today ⇒ Object
- #code_tomorrow ⇒ Object
- #code_tuesday? ⇒ Boolean
- #code_wednesday? ⇒ Boolean
- #code_week ⇒ Object
- #code_week_day ⇒ Object
- #code_week_days ⇒ Object
- #code_weeks ⇒ Object
- #code_year ⇒ Object
- #code_years ⇒ Object
- #code_yesterday ⇒ Object
- #code_zone ⇒ Object
-
#initialize(*args, **_kargs, &_block) ⇒ Time
constructor
A new instance of Time.
Methods inherited from Code::Object
code_new, #code_new, maybe, #name, repeat, |
Methods included from Concerns::Shared
#<=>, #==, #as_json, #blank?, #code_and, #code_as_json, #code_blank?, #code_compare, #code_deep_duplicate, #code_different, #code_duplicate, #code_equal, #code_exclamation_mark, #code_exclusive_range, #code_falsy?, code_fetch, #code_fetch, code_get, #code_get, #code_greater, #code_greater_or_equal, #code_inclusive_range, #code_inspect, #code_less, #code_less_or_equal, #code_methods, #code_name, #code_nothing?, #code_or, #code_presence, #code_presence_in, #code_present?, #code_self, code_set, #code_set, #code_something?, #code_strict_different, #code_strict_equal, #code_to_boolean, #code_to_class, #code_to_date, #code_to_decimal, #code_to_dictionary, #code_to_duration, #code_to_integer, #code_to_json, #code_to_list, #code_to_nothing, #code_to_parameter, #code_to_range, #code_to_string, #code_to_time, #code_truthy?, #eql?, #falsy?, #hash, #inspect, #multi_fetch, #nothing?, #present?, #sig, #something?, #succ, #to_code, #to_i, #to_json, #to_s, #truthy?
Constructor Details
#initialize(*args, **_kargs, &_block) ⇒ Time
Returns a new instance of Time.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/code/object/time.rb', line 62 def initialize(*args, **_kargs, &_block) ::Time.zone ||= DEFAULT_ZONE first = args.first self.raw = case first when String, ::String ::Time.zone.parse(first.to_s) || raise(Error) when Time first.raw.dup.in_time_zone(::Time.zone) when ::Time first.dup.in_time_zone(::Time.zone) when Date first.raw.to_time.in_time_zone(::Time.zone) when ::Date first.to_time.in_time_zone(::Time.zone) when ::ActiveSupport::TimeWithZone first.dup when Integer, Decimal, ::Integer, ::Float, ::BigDecimal code_value = first.to_code = (code_value.is_a?(Decimal) ? code_value.raw.to_r : code_value.raw) ::Time.zone.at() else ::Time.zone.now end end |
Class Method Details
.call(**args) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/code/object/time.rb', line 90 def self.call(**args) code_operator = args.fetch(:operator, nil).to_code code_arguments = args.fetch(:arguments, []).to_code code_value = code_arguments.code_first code_second = code_arguments.code_second case code_operator.to_s when "zone=" sig(args) { String } ::Time.zone = code_value.raw code_value when "zone" sig(args) ::Time.zone ||= DEFAULT_ZONE code_zone when "after?" sig(args) { (Date | Time).maybe } code_after?(code_value) when "before?" sig(args) { (Date | Time).maybe } code_before?(code_value) when "now" sig(args) code_now when "tomorrow" sig(args) code_tomorrow when "yesterday" sig(args) code_yesterday when "past?" sig(args) code_past? when "future?" sig(args) code_future? when "year" sig(args) code_year when "years" sig(args) code_years when "month" sig(args) code_month when "months" sig(args) code_months when "week" sig(args) code_week when "weeks" sig(args) code_weeks when "week_day" sig(args) code_week_day when "week_days" sig(args) code_week_days when "day" sig(args) code_day when "days" sig(args) code_days when "hour" sig(args) code_hour when "hours" sig(args) code_hours when "minute" sig(args) code_minute when "minutes" sig(args) code_minutes when "second" sig(args) code_second when "seconds" sig(args) code_seconds when "monday?" sig(args) code_monday? when "tuesday?" sig(args) code_tuesday? when "wednesday?" sig(args) code_wednesday? when "thursday?" sig(args) code_thursday? when "friday?" sig(args) code_friday? when "saturday?" sig(args) code_saturday? when "sunday?" sig(args) code_sunday? when "format" sig(args) { [String.maybe, { locale: String.maybe }] } if code_value.is_a?(Dictionary) code_format(nil, locale: code_value.code_get(:locale)) elsif code_second.something? code_format(code_value, locale: code_second.code_get(:locale)) else code_format(code_value) end when "january?" sig(args) code_january? when "february?" sig(args) code_february? when "march?" sig(args) code_march? when "april?" sig(args) code_april? when "may?" sig(args) code_may? when "june?" sig(args) code_june? when "july?" sig(args) code_july? when "august?" sig(args) code_august? when "september?" sig(args) code_september? when "october?" sig(args) code_october? when "november?" sig(args) code_november? when "december?" sig(args) code_december? when "add" sig(args) do { year: (String | Integer).maybe, years: (String | Integer).maybe, month: (String | Integer).maybe, months: (String | Integer).maybe, day: (String | Integer).maybe, days: (String | Integer).maybe, week_day: (String | Integer).maybe, week_days: (String | Integer).maybe, week: (String | Integer).maybe, weeks: (String | Integer).maybe, hour: (String | Integer).maybe, hours: (String | Integer).maybe, minute: (String | Integer).maybe, minutes: (String | Integer).maybe, second: (String | Integer).maybe, seconds: (String | Integer).maybe } end if code_value.nothing? code_add else code_add( year: code_value.code_get(:year), years: code_value.code_get(:years), month: code_value.code_get(:month), months: code_value.code_get(:months), day: code_value.code_get(:day), days: code_value.code_get(:days), week_day: code_value.code_get(:week_day), week_days: code_value.code_get(:week_days), week: code_value.code_get(:week), weeks: code_value.code_get(:weeks), hour: code_value.code_get(:hour), hours: code_value.code_get(:hours), minute: code_value.code_get(:minute), minutes: code_value.code_get(:minutes), second: code_value.code_get(:second), seconds: code_value.code_get(:seconds) ) end when "substract" sig(args) do { year: (String | Integer).maybe, years: (String | Integer).maybe, month: (String | Integer).maybe, months: (String | Integer).maybe, day: (String | Integer).maybe, days: (String | Integer).maybe, week_day: (String | Integer).maybe, week_days: (String | Integer).maybe, week: (String | Integer).maybe, weeks: (String | Integer).maybe, hour: (String | Integer).maybe, hours: (String | Integer).maybe, minute: (String | Integer).maybe, minutes: (String | Integer).maybe, second: (String | Integer).maybe, seconds: (String | Integer).maybe } end if code_value.nothing? code_substract else code_substract( year: code_value.code_get(:year), years: code_value.code_get(:years), month: code_value.code_get(:month), months: code_value.code_get(:months), day: code_value.code_get(:day), days: code_value.code_get(:days), week_day: code_value.code_get(:week_day), week_days: code_value.code_get(:week_days), week: code_value.code_get(:week), weeks: code_value.code_get(:weeks), hour: code_value.code_get(:hour), hours: code_value.code_get(:hours), minute: code_value.code_get(:minute), minutes: code_value.code_get(:minutes), second: code_value.code_get(:second), seconds: code_value.code_get(:seconds) ) end when "change" sig(args) do { year: (String | Integer).maybe, years: (String | Integer).maybe, month: (String | Integer).maybe, months: (String | Integer).maybe, day: (String | Integer).maybe, days: (String | Integer).maybe, week_day: (String | Integer).maybe, week_days: (String | Integer).maybe, week: (String | Integer).maybe, weeks: (String | Integer).maybe, hour: (String | Integer).maybe, hours: (String | Integer).maybe, minute: (String | Integer).maybe, minutes: (String | Integer).maybe, second: (String | Integer).maybe, seconds: (String | Integer).maybe } end if code_value.nothing? code_change else code_change( year: code_value.code_get(:year), years: code_value.code_get(:years), month: code_value.code_get(:month), months: code_value.code_get(:months), day: code_value.code_get(:day), days: code_value.code_get(:days), week_day: code_value.code_get(:week_day), week_days: code_value.code_get(:week_days), week: code_value.code_get(:week), weeks: code_value.code_get(:weeks), hour: code_value.code_get(:hour), hours: code_value.code_get(:hours), minute: code_value.code_get(:minute), minutes: code_value.code_get(:minutes), second: code_value.code_get(:second), seconds: code_value.code_get(:seconds) ) end else super end end |
Instance Method Details
#call(**args) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/code/object/time.rb', line 382 def call(**args) code_operator = args.fetch(:operator, nil).to_code code_arguments = args.fetch(:arguments, []).to_code code_value = code_arguments.code_first code_second = code_arguments.code_second case code_operator.to_s when "zone" sig(args) code_zone when "after?" sig(args) { (Date | Time).maybe } code_after?(code_value) when "before?" sig(args) { (Date | Time).maybe } code_before?(code_value) when "tomorrow" sig(args) code_tomorrow when "yesterday" sig(args) code_yesterday when "past?" sig(args) code_past? when "future?" sig(args) code_future? when "year" sig(args) code_year when "years" sig(args) code_years when "month" sig(args) code_month when "months" sig(args) code_months when "week" sig(args) code_week when "weeks" sig(args) code_weeks when "week_day" sig(args) code_week_day when "week_days" sig(args) code_week_days when "day" sig(args) code_day when "days" sig(args) code_days when "hour" sig(args) code_hour when "hours" sig(args) code_hours when "minute" sig(args) code_minute when "minutes" sig(args) code_minutes when "second" sig(args) code_second when "seconds" sig(args) code_seconds when "monday?" sig(args) code_monday? when "tuesday?" sig(args) code_tuesday? when "wednesday?" sig(args) code_wednesday? when "thursday?" sig(args) code_thursday? when "friday?" sig(args) code_friday? when "saturday?" sig(args) code_saturday? when "sunday?" sig(args) code_sunday? when "format" sig(args) { [String.maybe, { locale: String.maybe }] } if code_value.is_a?(Dictionary) code_format(nil, locale: code_value.code_get(:locale)) elsif code_second.something? code_format(code_value, locale: code_second.code_get(:locale)) else code_format(code_value) end when "january?" sig(args) code_january? when "february?" sig(args) code_february? when "march?" sig(args) code_march? when "april?" sig(args) code_april? when "may?" sig(args) code_may? when "june?" sig(args) code_june? when "july?" sig(args) code_july? when "august?" sig(args) code_august? when "september?" sig(args) code_september? when "october?" sig(args) code_october? when "november?" sig(args) code_november? when "december?" sig(args) code_december? when "add" sig(args) do { year: (String | Integer).maybe, years: (String | Integer).maybe, month: (String | Integer).maybe, months: (String | Integer).maybe, day: (String | Integer).maybe, days: (String | Integer).maybe, week_day: (String | Integer).maybe, week_days: (String | Integer).maybe, week: (String | Integer).maybe, weeks: (String | Integer).maybe, hour: (String | Integer).maybe, hours: (String | Integer).maybe, minute: (String | Integer).maybe, minutes: (String | Integer).maybe, second: (String | Integer).maybe, seconds: (String | Integer).maybe } end if code_value.nothing? code_add else code_add( year: code_value.code_get(:year), years: code_value.code_get(:years), month: code_value.code_get(:month), months: code_value.code_get(:months), day: code_value.code_get(:day), days: code_value.code_get(:days), week_day: code_value.code_get(:week_day), week_days: code_value.code_get(:week_days), week: code_value.code_get(:week), weeks: code_value.code_get(:weeks), hour: code_value.code_get(:hour), hours: code_value.code_get(:hours), minute: code_value.code_get(:minute), minutes: code_value.code_get(:minutes), second: code_value.code_get(:second), seconds: code_value.code_get(:seconds) ) end when "substract" sig(args) do { year: (String | Integer).maybe, years: (String | Integer).maybe, month: (String | Integer).maybe, months: (String | Integer).maybe, day: (String | Integer).maybe, days: (String | Integer).maybe, week_day: (String | Integer).maybe, week_days: (String | Integer).maybe, week: (String | Integer).maybe, weeks: (String | Integer).maybe, hour: (String | Integer).maybe, hours: (String | Integer).maybe, minute: (String | Integer).maybe, minutes: (String | Integer).maybe, second: (String | Integer).maybe, seconds: (String | Integer).maybe } end if code_value.nothing? code_substract else code_substract( year: code_value.code_get(:year), years: code_value.code_get(:years), month: code_value.code_get(:month), months: code_value.code_get(:months), day: code_value.code_get(:day), days: code_value.code_get(:days), week_day: code_value.code_get(:week_day), week_days: code_value.code_get(:week_days), week: code_value.code_get(:week), weeks: code_value.code_get(:weeks), hour: code_value.code_get(:hour), hours: code_value.code_get(:hours), minute: code_value.code_get(:minute), minutes: code_value.code_get(:minutes), second: code_value.code_get(:second), seconds: code_value.code_get(:seconds) ) end when "change" sig(args) do { year: (String | Integer).maybe, years: (String | Integer).maybe, month: (String | Integer).maybe, months: (String | Integer).maybe, day: (String | Integer).maybe, days: (String | Integer).maybe, week_day: (String | Integer).maybe, week_days: (String | Integer).maybe, week: (String | Integer).maybe, weeks: (String | Integer).maybe, hour: (String | Integer).maybe, hours: (String | Integer).maybe, minute: (String | Integer).maybe, minutes: (String | Integer).maybe, second: (String | Integer).maybe, seconds: (String | Integer).maybe } end if code_value.nothing? code_change else code_change( year: code_value.code_get(:year), years: code_value.code_get(:years), month: code_value.code_get(:month), months: code_value.code_get(:months), day: code_value.code_get(:day), days: code_value.code_get(:days), week_day: code_value.code_get(:week_day), week_days: code_value.code_get(:week_days), week: code_value.code_get(:week), weeks: code_value.code_get(:weeks), hour: code_value.code_get(:hour), hours: code_value.code_get(:hours), minute: code_value.code_get(:minute), minutes: code_value.code_get(:minutes), second: code_value.code_get(:second), seconds: code_value.code_get(:seconds) ) end else super end end |
#code_add(year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil) ⇒ Object
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 |
# File 'lib/code/object/time.rb', line 864 def code_add( year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil ) code_year = year.to_code.nothing? ? years.to_code : year.to_code code_month = month.to_code.nothing? ? months.to_code : month.to_code code_day = day.to_code.nothing? ? days.to_code : day.to_code code_week_day = week_day.to_code.nothing? ? week_days.to_code : week_day.to_code code_week = week.to_code.nothing? ? weeks.to_code : week.to_code code_hour = hour.to_code.nothing? ? hours.to_code : hour.to_code code_minute = minute.to_code.nothing? ? minutes.to_code : minute.to_code code_second = second.to_code.nothing? ? seconds.to_code : second.to_code year = code_years.code_to_integer.raw + code_year.code_to_integer.raw month = code_months.code_to_integer.raw + code_month.code_to_integer.raw day = code_days.code_to_integer.raw + code_day.code_to_integer.raw week_day = code_week_days.code_to_integer.raw + code_week_day.code_to_integer.raw week = code_weeks.code_to_integer.raw + code_week.code_to_integer.raw hour = code_hours.code_to_integer.raw + code_hour.code_to_integer.raw minute = code_minutes.code_to_integer.raw + code_minute.code_to_integer.raw second = code_seconds.code_to_integer.raw + code_second.code_to_integer.raw code_change( year: year, month: month, day: day, week_day: week_day, week: week, hour: hour, minute: minute, second: second ) end |
#code_after?(other = nil) ⇒ Boolean
662 663 664 665 666 667 |
# File 'lib/code/object/time.rb', line 662 def code_after?(other = nil) code_other = other.to_code code_other = Time.new if code_other.nothing? Boolean.new(raw.after?(code_other.raw)) end |
#code_april? ⇒ Boolean
788 789 790 |
# File 'lib/code/object/time.rb', line 788 def code_april? code_month.code_four? end |
#code_august? ⇒ Boolean
804 805 806 |
# File 'lib/code/object/time.rb', line 804 def code_august? code_month.code_eight? end |
#code_before?(other = nil) ⇒ Boolean
669 670 671 672 673 674 |
# File 'lib/code/object/time.rb', line 669 def code_before?(other = nil) code_other = other.to_code code_other = Time.new if code_other.nothing? Boolean.new(raw.before?(code_other.raw)) end |
#code_change(year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil) ⇒ Object
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'lib/code/object/time.rb', line 968 def code_change( year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil ) code_year = year.to_code.nothing? ? years.to_code : year.to_code code_month = month.to_code.nothing? ? months.to_code : month.to_code code_day = day.to_code.nothing? ? days.to_code : day.to_code code_week_day = week_day.to_code.nothing? ? week_days.to_code : week_day.to_code code_week = week.to_code.nothing? ? weeks.to_code : week.to_code code_hour = hour.to_code.nothing? ? hours.to_code : hour.to_code code_minute = minute.to_code.nothing? ? minutes.to_code : minute.to_code code_second = second.to_code.nothing? ? seconds.to_code : second.to_code year = code_year.raw || code_years.raw month = code_month.raw || code_months.raw day = code_day.raw || code_days.raw wday = code_week_day.raw || code_week_days.raw cweek = code_week.raw || code_weeks.raw hour = code_hour.raw || code_hours.raw min = code_minute.raw || code_minutes.raw sec = code_second.raw || code_seconds.raw dup = raw.dup dup += (year - raw.year).years dup += (month - raw.month).months dup += (day - raw.day).days dup += (wday - raw.wday).days dup += (cweek - raw.to_date.cweek).weeks dup += (hour - raw.hour).hours dup += (min - raw.min).minutes dup += (sec - raw.sec).seconds Time.new(dup) end |
#code_current ⇒ Object
852 853 854 |
# File 'lib/code/object/time.rb', line 852 def code_current Time.new end |
#code_day ⇒ Object
716 717 718 |
# File 'lib/code/object/time.rb', line 716 def code_day Integer.new(raw.day) end |
#code_days ⇒ Object
720 721 722 |
# File 'lib/code/object/time.rb', line 720 def code_days Integer.new(raw.day) end |
#code_december? ⇒ Boolean
820 821 822 |
# File 'lib/code/object/time.rb', line 820 def code_december? code_month.code_twelve? end |
#code_february? ⇒ Boolean
780 781 782 |
# File 'lib/code/object/time.rb', line 780 def code_february? code_month.code_two? end |
#code_format(format, locale: nil) ⇒ Object
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'lib/code/object/time.rb', line 824 def code_format(format, locale: nil) code_format = format.to_code code_locale = locale.to_code requested_locale = code_locale.raw&.to_s locale = requested_locale&.presence_in(LOCALES)&.to_sym locale ||= ::I18n.locale locale = ::I18n.locale unless ::I18n.available_locales.include?( locale.to_sym ) format = code_format.raw || :default format = format.to_sym if ::I18n.exists?( "time.formats.#{format}", locale ) String.new(::I18n.l(raw, format: format, locale: locale)) end |
#code_friday? ⇒ Boolean
764 765 766 |
# File 'lib/code/object/time.rb', line 764 def code_friday? code_week_day.code_five? end |
#code_future? ⇒ Boolean
680 681 682 |
# File 'lib/code/object/time.rb', line 680 def code_future? code_after? end |
#code_hour ⇒ Object
724 725 726 |
# File 'lib/code/object/time.rb', line 724 def code_hour Integer.new(raw.hour) end |
#code_hours ⇒ Object
728 729 730 |
# File 'lib/code/object/time.rb', line 728 def code_hours Integer.new(raw.hour) end |
#code_january? ⇒ Boolean
776 777 778 |
# File 'lib/code/object/time.rb', line 776 def code_january? code_month.code_one? end |
#code_july? ⇒ Boolean
800 801 802 |
# File 'lib/code/object/time.rb', line 800 def code_july? code_month.code_seven? end |
#code_june? ⇒ Boolean
796 797 798 |
# File 'lib/code/object/time.rb', line 796 def code_june? code_month.code_six? end |
#code_march? ⇒ Boolean
784 785 786 |
# File 'lib/code/object/time.rb', line 784 def code_march? code_month.code_three? end |
#code_may? ⇒ Boolean
792 793 794 |
# File 'lib/code/object/time.rb', line 792 def code_may? code_month.code_five? end |
#code_minute ⇒ Object
732 733 734 |
# File 'lib/code/object/time.rb', line 732 def code_minute Integer.new(raw.min) end |
#code_minutes ⇒ Object
736 737 738 |
# File 'lib/code/object/time.rb', line 736 def code_minutes Integer.new(raw.min) end |
#code_monday? ⇒ Boolean
748 749 750 |
# File 'lib/code/object/time.rb', line 748 def code_monday? code_week_day.code_one? end |
#code_month ⇒ Object
692 693 694 |
# File 'lib/code/object/time.rb', line 692 def code_month Integer.new(raw.month) end |
#code_months ⇒ Object
696 697 698 |
# File 'lib/code/object/time.rb', line 696 def code_months Integer.new(raw.month) end |
#code_november? ⇒ Boolean
816 817 818 |
# File 'lib/code/object/time.rb', line 816 def code_november? code_month.code_eleven? end |
#code_october? ⇒ Boolean
812 813 814 |
# File 'lib/code/object/time.rb', line 812 def code_october? code_month.code_ten? end |
#code_past? ⇒ Boolean
676 677 678 |
# File 'lib/code/object/time.rb', line 676 def code_past? code_before? end |
#code_saturday? ⇒ Boolean
768 769 770 |
# File 'lib/code/object/time.rb', line 768 def code_saturday? code_week_day.code_six? end |
#code_second ⇒ Object
740 741 742 |
# File 'lib/code/object/time.rb', line 740 def code_second Integer.new(raw.sec) end |
#code_seconds ⇒ Object
744 745 746 |
# File 'lib/code/object/time.rb', line 744 def code_seconds Integer.new(raw.sec) end |
#code_september? ⇒ Boolean
808 809 810 |
# File 'lib/code/object/time.rb', line 808 def code_september? code_month.code_nine? end |
#code_substract(year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil) ⇒ Object
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
# File 'lib/code/object/time.rb', line 916 def code_substract( year: nil, years: nil, month: nil, months: nil, day: nil, days: nil, week_day: nil, week_days: nil, week: nil, weeks: nil, hour: nil, hours: nil, minute: nil, minutes: nil, second: nil, seconds: nil ) code_year = year.to_code.nothing? ? years.to_code : year.to_code code_month = month.to_code.nothing? ? months.to_code : month.to_code code_day = day.to_code.nothing? ? days.to_code : day.to_code code_week_day = week_day.to_code.nothing? ? week_days.to_code : week_day.to_code code_week = week.to_code.nothing? ? weeks.to_code : week.to_code code_hour = hour.to_code.nothing? ? hours.to_code : hour.to_code code_minute = minute.to_code.nothing? ? minutes.to_code : minute.to_code code_second = second.to_code.nothing? ? seconds.to_code : second.to_code year = code_years.code_to_integer.raw - code_year.code_to_integer.raw month = code_months.code_to_integer.raw - code_month.code_to_integer.raw day = code_days.code_to_integer.raw - code_day.code_to_integer.raw week_day = code_week_days.code_to_integer.raw - code_week_day.code_to_integer.raw week = code_weeks.code_to_integer.raw - code_week.code_to_integer.raw hour = code_hours.code_to_integer.raw - code_hour.code_to_integer.raw minute = code_minutes.code_to_integer.raw - code_minute.code_to_integer.raw second = code_seconds.code_to_integer.raw - code_second.code_to_integer.raw code_change( year: year, month: month, day: day, week_day: week_day, week: week, hour: hour, minute: minute, second: second ) end |
#code_sunday? ⇒ Boolean
772 773 774 |
# File 'lib/code/object/time.rb', line 772 def code_sunday? code_week_day.code_zero? end |
#code_thursday? ⇒ Boolean
760 761 762 |
# File 'lib/code/object/time.rb', line 760 def code_thursday? code_week_day.code_four? end |
#code_today ⇒ Object
844 845 846 |
# File 'lib/code/object/time.rb', line 844 def code_today Time.new end |
#code_tomorrow ⇒ Object
856 857 858 |
# File 'lib/code/object/time.rb', line 856 def code_tomorrow code_add(day: 1) end |
#code_tuesday? ⇒ Boolean
752 753 754 |
# File 'lib/code/object/time.rb', line 752 def code_tuesday? code_week_day.code_two? end |
#code_wednesday? ⇒ Boolean
756 757 758 |
# File 'lib/code/object/time.rb', line 756 def code_wednesday? code_week_day.code_three? end |
#code_week ⇒ Object
700 701 702 |
# File 'lib/code/object/time.rb', line 700 def code_week Integer.new(raw.to_date.cweek) end |
#code_week_day ⇒ Object
708 709 710 |
# File 'lib/code/object/time.rb', line 708 def code_week_day Integer.new(raw.wday) end |
#code_week_days ⇒ Object
712 713 714 |
# File 'lib/code/object/time.rb', line 712 def code_week_days Integer.new(raw.wday) end |
#code_weeks ⇒ Object
704 705 706 |
# File 'lib/code/object/time.rb', line 704 def code_weeks Integer.new(raw.to_date.cweek) end |
#code_year ⇒ Object
684 685 686 |
# File 'lib/code/object/time.rb', line 684 def code_year Integer.new(raw.year) end |
#code_years ⇒ Object
688 689 690 |
# File 'lib/code/object/time.rb', line 688 def code_years Integer.new(raw.year) end |
#code_yesterday ⇒ Object
860 861 862 |
# File 'lib/code/object/time.rb', line 860 def code_yesterday code_substract(day: 1) end |