Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

DateTimeValue.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Copyright (c) 2016 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.impl.expr;
  14. import java.math.BigDecimal;
  15. import java.time.LocalDateTime;
  16. import com.healthmarketscience.jackcess.expr.LocaleContext;
  17. import com.healthmarketscience.jackcess.expr.Value;
  18. import com.healthmarketscience.jackcess.impl.ColumnImpl;
  19. /**
  20. *
  21. * @author James Ahlborn
  22. */
  23. public class DateTimeValue extends BaseValue
  24. {
  25. private final Type _type;
  26. private final LocalDateTime _val;
  27. public DateTimeValue(Type type, LocalDateTime val) {
  28. if(!type.isTemporal()) {
  29. throw new IllegalArgumentException("invalid date/time type");
  30. }
  31. _type = type;
  32. _val = val;
  33. }
  34. public Type getType() {
  35. return _type;
  36. }
  37. public Object get() {
  38. return _val;
  39. }
  40. protected Double getNumber(LocaleContext ctx) {
  41. return ColumnImpl.toDateDouble(_val);
  42. }
  43. @Override
  44. public boolean getAsBoolean(LocaleContext ctx) {
  45. // ms access seems to treat dates/times as "true"
  46. return true;
  47. }
  48. @Override
  49. public String getAsString(LocaleContext ctx) {
  50. return ValueSupport.getDateFormatForType(ctx, getType()).format(_val);
  51. }
  52. @Override
  53. public LocalDateTime getAsLocalDateTime(LocaleContext ctx) {
  54. return _val;
  55. }
  56. @Override
  57. public Value getAsDateTimeValue(LocaleContext ctx) {
  58. return this;
  59. }
  60. @Override
  61. public Integer getAsLongInt(LocaleContext ctx) {
  62. return roundToLongInt(ctx);
  63. }
  64. @Override
  65. public Double getAsDouble(LocaleContext ctx) {
  66. return getNumber(ctx);
  67. }
  68. @Override
  69. public BigDecimal getAsBigDecimal(LocaleContext ctx) {
  70. return BigDecimal.valueOf(getNumber(ctx));
  71. }
  72. }