1 /* 2 * hunt-time: A time library for D programming language. 3 * 4 * Copyright (C) 2015-2018 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.time.format.FormatStyle; 13 14 /** 15 * Enumeration of the style of a localized date, time or date-time formatter. 16 * !(p) 17 * These styles are used when obtaining a date-time style from configuration. 18 * See {@link DateTimeFormatter} and {@link DateTimeFormatterBuilder} for usage. 19 * 20 * @implSpec 21 * This is an immutable and thread-safe enum. 22 * 23 * @since 1.8 24 */ 25 public class FormatStyle { 26 // ordered from large to small 27 /** 28 * Full text style, with the most detail. 29 * For example, the format might be 'Tuesday, April 12, 1952 AD' or '3:30:42pm PST'. 30 */ 31 static FormatStyle FULL; 32 /** 33 * Long text style, with lots of detail. 34 * For example, the format might be 'January 12, 1952'. 35 */ 36 static FormatStyle LONG; 37 /** 38 * Medium text style, with some detail. 39 * For example, the format might be 'Jan 12, 1952'. 40 */ 41 static FormatStyle MEDIUM; 42 /** 43 * Short text style, typically numeric. 44 * For example, the format might be '12.13.52' or '3:30pm'. 45 */ 46 static FormatStyle SHORT; 47 48 // static this() 49 // { 50 // FULL = new FormatStyle(0,"FULL"); 51 // LONG = new FormatStyle(1,"LONG"); 52 // MEDIUM = new FormatStyle(2,"MEDIUM"); 53 // SHORT = new FormatStyle(3,"SHORT"); 54 // } 55 56 private int _ordinal; 57 private string _name; 58 59 this(int ord,string name) 60 { 61 _ordinal = ord; 62 _name = name; 63 } 64 65 public int ordinal() 66 { 67 return _ordinal; 68 } 69 70 public string name() 71 { 72 return _name; 73 } 74 75 bool opEquals(const FormatStyle h) nothrow { 76 return _name == h._name ; 77 } 78 79 bool opEquals(ref const FormatStyle h) nothrow { 80 return _name == h._name ; 81 } 82 83 override 84 bool opEquals(Object obj) { 85 if (this is obj) { 86 return true; 87 } 88 if (cast(FormatStyle)(obj) !is null) { 89 FormatStyle other = cast(FormatStyle) obj; 90 return _name == other._name; 91 } 92 return false; 93 } 94 }